Skip to content

Commit

Permalink
construct request once.
Browse files Browse the repository at this point in the history
  • Loading branch information
rmehta19 committed Oct 2, 2024
1 parent 05aa9cc commit 1466f0d
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions oauth2_http/java/com/google/auth/oauth2/S2A.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,21 +66,25 @@ private S2AConfig getS2AConfigFromMDS() {
transportFactory =
Iterables.getFirst(
ServiceLoader.load(HttpTransportFactory.class), OAuth2Utils.HTTP_TRANSPORT_FACTORY);
}
}

HttpRequest request;
try {
request =
transportFactory.create().createRequestFactory().buildGetRequest(genericUrl);
request.setParser(parser);
request.getHeaders().set(METADATA_FLAVOR, GOOGLE);
request.setThrowExceptionOnExecuteError(false);
} catch (IOException e) {
return S2AConfig.createBuilder().build();
}

for (int i = 0; i < MAX_MDS_PING_TRIES; i++) {
try {
HttpRequest request =
transportFactory.create().createRequestFactory().buildGetRequest(genericUrl);
request.setParser(parser);
request.getHeaders().set(METADATA_FLAVOR, GOOGLE);
request.setThrowExceptionOnExecuteError(false);
HttpResponse response = request.execute();

if (!response.isSuccessStatusCode()) {
continue;
}

InputStream content = response.getContent();
if (content == null) {
continue;
Expand Down

0 comments on commit 1466f0d

Please sign in to comment.