23
23
import build .bazel .remote .execution .v2 .RequestMetadata ;
24
24
import com .google .common .annotations .VisibleForTesting ;
25
25
import com .google .common .base .Strings ;
26
+ import com .google .common .collect .ImmutableSet ;
26
27
import com .google .devtools .build .lib .bazel .repository .downloader .Checksum ;
27
28
import com .google .devtools .build .lib .bazel .repository .downloader .Downloader ;
28
29
import com .google .devtools .build .lib .bazel .repository .downloader .HashOutputStream ;
@@ -171,7 +172,7 @@ static FetchBlobRequest newFetchBlobRequest(
171
172
requestBuilder .addQualifiers (
172
173
Qualifier .newBuilder ()
173
174
.setName (QUALIFIER_AUTH_HEADERS )
174
- .setValue (authHeadersJson (authHeaders ))
175
+ .setValue (authHeadersJson (urls , authHeaders ))
175
176
.build ());
176
177
}
177
178
@@ -197,15 +198,24 @@ private OutputStream newOutputStream(
197
198
return out ;
198
199
}
199
200
200
- private static String authHeadersJson (Map <URI , Map <String , String >> authHeaders ) {
201
+ private static String authHeadersJson (
202
+ List <URL > urls , Map <URI , Map <String , String >> authHeaders ) {
203
+ ImmutableSet <String > hostSet =
204
+ urls .stream ().map (URL ::getHost ).collect (ImmutableSet .toImmutableSet ());
201
205
Map <String , JsonObject > subObjects = new TreeMap <>();
202
206
for (Map .Entry <URI , Map <String , String >> entry : authHeaders .entrySet ()) {
207
+ URI uri = entry .getKey ();
208
+ // Only add headers that are relevant to the hosts.
209
+ if (!hostSet .contains (uri .getHost ())) {
210
+ continue ;
211
+ }
212
+
203
213
JsonObject subObject = new JsonObject ();
204
214
Map <String , String > orderedHeaders = new TreeMap <>(entry .getValue ());
205
215
for (Map .Entry <String , String > subEntry : orderedHeaders .entrySet ()) {
206
216
subObject .addProperty (subEntry .getKey (), subEntry .getValue ());
207
217
}
208
- subObjects .put (entry . getKey () .toString (), subObject );
218
+ subObjects .put (uri .toString (), subObject );
209
219
}
210
220
211
221
JsonObject authHeadersJson = new JsonObject ();
0 commit comments