Skip to content

Commit 793943c

Browse files
authored
cache library version (#2238)
so we don't need to read environment properties every call. Fixes #2234. This is not the approach proposed in the issue. As implemented in this PR, we will read the property once for every client instantiation, not once ever. Still, this should be fast enough, and we won't need to maintain double-check-locking mechanism.
1 parent 8e074f3 commit 793943c

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

google-cloud-core-http/src/main/java/com/google/cloud/http/HttpTransportOptions.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ public HttpRequestInitializer getHttpRequestInitializer(
149149
final HttpRequestInitializer delegate =
150150
scopedCredentials != null && scopedCredentials != NoCredentials.getInstance()
151151
? new HttpCredentialsAdapter(scopedCredentials) : null;
152+
final String xGoogHeader = getXGoogApiClientHeader(serviceOptions.getLibraryVersion());
152153
return new HttpRequestInitializer() {
153154
@Override
154155
public void initialize(HttpRequest httpRequest) throws IOException {
@@ -163,8 +164,7 @@ public void initialize(HttpRequest httpRequest) throws IOException {
163164
}
164165

165166
HttpHeaders headers = httpRequest.getHeaders();
166-
headers.set(
167-
"x-goog-api-client", getXGoogApiClientHeader(serviceOptions.getLibraryVersion()));
167+
headers.set("x-goog-api-client", xGoogHeader);
168168
}
169169
};
170170
}

0 commit comments

Comments
 (0)