Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import static com.google.common.base.MoreObjects.firstNonNull;

import com.google.api.client.extensions.appengine.http.UrlFetchTransport;
import com.google.api.client.http.HttpHeaders;
import com.google.api.client.http.HttpRequest;
import com.google.api.client.http.HttpRequestInitializer;
import com.google.api.client.http.HttpTransport;
Expand Down Expand Up @@ -154,10 +155,26 @@ public void initialize(HttpRequest httpRequest) throws IOException {
if (readTimeout >= 0) {
httpRequest.setReadTimeout(readTimeout);
}

HttpHeaders headers = httpRequest.getHeaders();
headers.set("x-goog-api-client", getXGoogApiClientHeader());
}
};
}

String getXGoogApiClientHeader() {
return String.format(
"gl-java/%s %s/%s",

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

getJavaVersion(),
ServiceOptions.getGoogApiClientLibName(),
ServiceOptions.getLibraryVersion());
}

private static String getJavaVersion() {
String javaVersion = Runtime.class.getPackage().getImplementationVersion();
return javaVersion != null ? javaVersion : "";
}

/**
* Returns the timeout in milliseconds to establish a connection. 0 is an infinite timeout, a
* negative number is the default value (20000).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -525,29 +525,29 @@ public TransportOptions getTransportOptions() {
/**
* Returns the application's name as a string in the format {@code gcloud-java/[version]}.
*/
public String getApplicationName() {
public static String getApplicationName() {
return APPLICATION_NAME;
}


/**
* Returns the library's name, {@code gcloud-java}, as a string.
*/
public String getLibraryName() {
public static String getLibraryName() {
return LIBRARY_NAME;
}

/**
* Returns the library's name used by x-goog-api-client header as a string.
*/
public String getGoogApiClientLibName() {
public static String getGoogApiClientLibName() {
return X_GOOGLE_CLIENT_HEADER_NAME;
}

/**
* Returns the library's version as a string.
*/
public String getLibraryVersion() {
public static String getLibraryVersion() {
return LIBRARY_VERSION;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

import com.google.auth.http.HttpTransportFactory;
import com.google.cloud.HttpTransportOptions.DefaultHttpTransportFactory;
import java.util.regex.Pattern;
import org.easymock.EasyMock;
import org.junit.Test;

Expand Down Expand Up @@ -60,4 +61,12 @@ public void testBaseHashCode() {
assertEquals(OPTIONS.hashCode(), OPTIONS_COPY.hashCode());
assertNotEquals(DEFAULT_OPTIONS.hashCode(), OPTIONS.hashCode());
}

@Test
public void testHeader() {
String expectedHeaderPattern = "^gl-java/.* gccl/.*";
assertTrue(Pattern.compile(expectedHeaderPattern)
.matcher(DEFAULT_OPTIONS.getXGoogApiClientHeader())
.find());
}
}
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@
<github.global.server>github</github.global.server>
<google.auth.version>0.6.0</google.auth.version>
<grpc.version>1.0.3</grpc.version>
<gax.version>0.6.0</gax.version>
<gax.version>0.6.1</gax.version>

This comment was marked as spam.

This comment was marked as spam.

<generatedProto.version>0.1.5</generatedProto.version>
<core.version>0.10.1-alpha-SNAPSHOT</core.version>
<beta.version>0.10.1-beta-SNAPSHOT</beta.version>
Expand Down