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 ;
@@ -165,7 +166,7 @@ static FetchBlobRequest newFetchBlobRequest(
165
166
requestBuilder .addQualifiers (
166
167
Qualifier .newBuilder ()
167
168
.setName (QUALIFIER_AUTH_HEADERS )
168
- .setValue (authHeadersJson (authHeaders ))
169
+ .setValue (authHeadersJson (urls , authHeaders ))
169
170
.build ());
170
171
}
171
172
@@ -190,15 +191,24 @@ private OutputStream newOutputStream(
190
191
return out ;
191
192
}
192
193
193
- private static String authHeadersJson (Map <URI , Map <String , String >> authHeaders ) {
194
+ private static String authHeadersJson (
195
+ List <URL > urls , Map <URI , Map <String , String >> authHeaders ) {
196
+ ImmutableSet <String > hostSet =
197
+ urls .stream ().map (URL ::getHost ).collect (ImmutableSet .toImmutableSet ());
194
198
Map <String , JsonObject > subObjects = new TreeMap <>();
195
199
for (Map .Entry <URI , Map <String , String >> entry : authHeaders .entrySet ()) {
200
+ URI uri = entry .getKey ();
201
+ // Only add headers that are relevant to the hosts.
202
+ if (!hostSet .contains (uri .getHost ())) {
203
+ continue ;
204
+ }
205
+
196
206
JsonObject subObject = new JsonObject ();
197
207
Map <String , String > orderedHeaders = new TreeMap <>(entry .getValue ());
198
208
for (Map .Entry <String , String > subEntry : orderedHeaders .entrySet ()) {
199
209
subObject .addProperty (subEntry .getKey (), subEntry .getValue ());
200
210
}
201
- subObjects .put (entry . getKey () .toString (), subObject );
211
+ subObjects .put (uri .toString (), subObject );
202
212
}
203
213
204
214
JsonObject authHeadersJson = new JsonObject ();
0 commit comments