Skip to content

Commit bfb4d9c

Browse files
authored
fix: user-agent should use identifier/version (#1425)
* fix: user-agent should use identifier/version * test: inline USER_AGENT_SUFFIX in test
1 parent 57d7efe commit bfb4d9c

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

google-api-client/src/main/java/com/google/api/client/googleapis/services/AbstractGoogleClientRequest.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -126,9 +126,10 @@ protected AbstractGoogleClientRequest(AbstractGoogleClient abstractGoogleClient,
126126
// application name
127127
String applicationName = abstractGoogleClient.getApplicationName();
128128
if (applicationName != null) {
129-
requestHeaders.setUserAgent(applicationName + " " + USER_AGENT_SUFFIX);
129+
requestHeaders.setUserAgent(applicationName + " " + USER_AGENT_SUFFIX + "/"
130+
+ GoogleUtils.VERSION);
130131
} else {
131-
requestHeaders.setUserAgent(USER_AGENT_SUFFIX);
132+
requestHeaders.setUserAgent(USER_AGENT_SUFFIX + "/" + GoogleUtils.VERSION);
132133
}
133134
// Set the header for the Api Client version (Java and OS version)
134135
requestHeaders.set(API_VERSION_HEADER, ApiClientVersion.DEFAULT_VERSION);

google-api-client/src/test/java/com/google/api/client/googleapis/services/AbstractGoogleClientRequestTest.java

+4-2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
package com.google.api.client.googleapis.services;
1414

15+
import com.google.api.client.googleapis.GoogleUtils;
1516
import com.google.api.client.googleapis.services.AbstractGoogleClientRequest.ApiClientVersion;
1617
import com.google.api.client.googleapis.testing.services.MockGoogleClient;
1718
import com.google.api.client.googleapis.testing.services.MockGoogleClientRequest;
@@ -203,7 +204,7 @@ public void testUserAgentSuffix() throws Exception {
203204
// Specify an Application Name.
204205
String applicationName = "Test Application";
205206
transport.expectedUserAgent = applicationName + " "
206-
+ AbstractGoogleClientRequest.USER_AGENT_SUFFIX + " "
207+
+ "Google-API-Java-Client/" + GoogleUtils.VERSION + " "
207208
+ HttpRequest.USER_AGENT_SUFFIX;
208209
MockGoogleClient client = new MockGoogleClient.Builder(
209210
transport, ROOT_URL, SERVICE_PATH, JSON_OBJECT_PARSER, null).setApplicationName(
@@ -215,7 +216,8 @@ public void testUserAgentSuffix() throws Exception {
215216

216217
public void testUserAgent() throws IOException {
217218
AssertUserAgentTransport transport = new AssertUserAgentTransport();
218-
transport.expectedUserAgent = AbstractGoogleClientRequest.USER_AGENT_SUFFIX + " " + HttpRequest.USER_AGENT_SUFFIX;
219+
transport.expectedUserAgent = "Google-API-Java-Client/" + GoogleUtils.VERSION + " "
220+
+ HttpRequest.USER_AGENT_SUFFIX;
219221
// Don't specify an Application Name.
220222
MockGoogleClient client = new MockGoogleClient.Builder(
221223
transport, ROOT_URL, SERVICE_PATH, JSON_OBJECT_PARSER, null).build();

0 commit comments

Comments
 (0)