Skip to content

Commit

Permalink
fix: user-agent should use identifier/version (#1425)
Browse files Browse the repository at this point in the history
* fix: user-agent should use identifier/version

* test: inline USER_AGENT_SUFFIX in test
  • Loading branch information
chingor13 committed Nov 21, 2019
1 parent 57d7efe commit bfb4d9c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
Expand Up @@ -126,9 +126,10 @@ protected AbstractGoogleClientRequest(AbstractGoogleClient abstractGoogleClient,
// application name
String applicationName = abstractGoogleClient.getApplicationName();
if (applicationName != null) {
requestHeaders.setUserAgent(applicationName + " " + USER_AGENT_SUFFIX);
requestHeaders.setUserAgent(applicationName + " " + USER_AGENT_SUFFIX + "/"
+ GoogleUtils.VERSION);
} else {
requestHeaders.setUserAgent(USER_AGENT_SUFFIX);
requestHeaders.setUserAgent(USER_AGENT_SUFFIX + "/" + GoogleUtils.VERSION);
}
// Set the header for the Api Client version (Java and OS version)
requestHeaders.set(API_VERSION_HEADER, ApiClientVersion.DEFAULT_VERSION);
Expand Down
Expand Up @@ -12,6 +12,7 @@

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

import com.google.api.client.googleapis.GoogleUtils;
import com.google.api.client.googleapis.services.AbstractGoogleClientRequest.ApiClientVersion;
import com.google.api.client.googleapis.testing.services.MockGoogleClient;
import com.google.api.client.googleapis.testing.services.MockGoogleClientRequest;
Expand Down Expand Up @@ -203,7 +204,7 @@ public void testUserAgentSuffix() throws Exception {
// Specify an Application Name.
String applicationName = "Test Application";
transport.expectedUserAgent = applicationName + " "
+ AbstractGoogleClientRequest.USER_AGENT_SUFFIX + " "
+ "Google-API-Java-Client/" + GoogleUtils.VERSION + " "
+ HttpRequest.USER_AGENT_SUFFIX;
MockGoogleClient client = new MockGoogleClient.Builder(
transport, ROOT_URL, SERVICE_PATH, JSON_OBJECT_PARSER, null).setApplicationName(
Expand All @@ -215,7 +216,8 @@ public void testUserAgentSuffix() throws Exception {

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

0 comments on commit bfb4d9c

Please sign in to comment.