Skip to content

Commit 443340a

Browse files
chris-camposcopybara-github
authored andcommitted
Add header support for HttpStreamFactory
This is a roll forward of 8ffded8 BUG=481544451 GWSQ_IGNORE: chriscampos@google.com PiperOrigin-RevId: 882689078 Change-Id: I62e6d011bfcee3a7d70040a764c106103eff5e32
1 parent 87d136b commit 443340a

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

java/com/google/copybara/remotefile/GclientHttpStreamFactory.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import com.google.api.client.http.HttpRequest;
2323
import com.google.api.client.http.HttpTransport;
2424
import com.google.api.client.http.javanet.NetHttpTransport;
25+
import com.google.common.collect.ImmutableMultimap;
2526
import com.google.copybara.credentials.CredentialIssuingException;
2627
import com.google.copybara.credentials.CredentialRetrievalException;
2728
import com.google.copybara.http.auth.AuthInterceptor;
@@ -50,7 +51,8 @@ public GclientHttpStreamFactory(HttpTransport javaNet, Duration timeout) {
5051
}
5152

5253
@Override
53-
public InputStream open(URL url, @Nullable AuthInterceptor auth)
54+
public InputStream open(
55+
URL url, @Nullable AuthInterceptor auth, ImmutableMultimap<String, String> headers)
5456
throws IOException, CredentialRetrievalException, CredentialIssuingException {
5557
HttpRequest req =
5658
javaNet
@@ -59,6 +61,7 @@ public InputStream open(URL url, @Nullable AuthInterceptor auth)
5961
.setReadTimeout((int) timeout.toMillis())
6062
.setConnectTimeout((int) timeout.toMillis())
6163
.setUseRawRedirectUrls(true);
64+
headers.forEach((k, v) -> req.getHeaders().set(k, v));
6265
if (auth != null) {
6366
req.setInterceptor(auth.interceptor());
6467
}

java/com/google/copybara/remotefile/HttpStreamFactory.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
package com.google.copybara.remotefile;
1818

19+
import com.google.common.collect.ImmutableMultimap;
1920
import com.google.copybara.credentials.CredentialIssuingException;
2021
import com.google.copybara.credentials.CredentialRetrievalException;
2122
import com.google.copybara.http.auth.AuthInterceptor;
@@ -35,6 +36,19 @@ public interface HttpStreamFactory {
3536
* @param url The URL to open.
3637
* @param auth The interceptor to use for authentication. If null, no authentication will be used.
3738
*/
38-
InputStream open(URL url, @Nullable AuthInterceptor auth)
39+
default InputStream open(URL url, @Nullable AuthInterceptor auth)
40+
throws IOException, CredentialRetrievalException, CredentialIssuingException {
41+
return open(url, auth, ImmutableMultimap.of());
42+
}
43+
44+
/**
45+
* Open the referenced URL and return the stream to the contents.
46+
*
47+
* @param url The URL to open.
48+
* @param auth The interceptor to use for authentication. If null, no authentication will be used.
49+
* @param headers The headers to send in the HTTP request.
50+
*/
51+
InputStream open(
52+
URL url, @Nullable AuthInterceptor auth, ImmutableMultimap<String, String> headers)
3953
throws IOException, CredentialRetrievalException, CredentialIssuingException;
4054
}

0 commit comments

Comments
 (0)