Skip to content
Permalink
Browse files
fix: user-agent should use identifier/version (#1425)
* 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 bfb4d9cacdadd8065be07b1bf0c22ea7aeb94d97
@@ -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);
@@ -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;
@@ -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(
@@ -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();

0 comments on commit bfb4d9c

Please sign in to comment.