Skip to content

Commit e56814f

Browse files
committed
cache library version
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 b191ab3 commit e56814f

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)