From 8f4222466d1aa6eb445bbe0f62b886051fa154a4 Mon Sep 17 00:00:00 2001 From: Marco Ziccardi Date: Mon, 26 Sep 2016 08:06:57 +0200 Subject: [PATCH] Update DatastoreOptions.httpRequestInitializer to set User-Agent --- .../google/cloud/datastore/DatastoreOptions.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/google-cloud-datastore/src/main/java/com/google/cloud/datastore/DatastoreOptions.java b/google-cloud-datastore/src/main/java/com/google/cloud/datastore/DatastoreOptions.java index ddd32c3d7adf..f63892affdaa 100644 --- a/google-cloud-datastore/src/main/java/com/google/cloud/datastore/DatastoreOptions.java +++ b/google-cloud-datastore/src/main/java/com/google/cloud/datastore/DatastoreOptions.java @@ -18,6 +18,8 @@ import static com.google.cloud.datastore.Validator.validateNamespace; +import com.google.api.client.http.HttpRequest; +import com.google.api.client.http.HttpRequestInitializer; import com.google.cloud.HttpServiceOptions; import com.google.cloud.datastore.spi.DatastoreRpc; import com.google.cloud.datastore.spi.DatastoreRpcFactory; @@ -25,6 +27,7 @@ import com.google.common.base.MoreObjects; import com.google.common.collect.ImmutableSet; +import java.io.IOException; import java.lang.reflect.Method; import java.util.Objects; import java.util.Set; @@ -90,6 +93,18 @@ private DatastoreOptions(Builder builder) { namespace = builder.namespace != null ? builder.namespace : defaultNamespace(); } + @Override + public HttpRequestInitializer httpRequestInitializer() { + final HttpRequestInitializer delegate = super.httpRequestInitializer(); + return new HttpRequestInitializer() { + @Override + public void initialize(HttpRequest httpRequest) throws IOException { + delegate.initialize(httpRequest); + httpRequest.getHeaders().setUserAgent(applicationName()); + } + }; + } + @Override protected String defaultHost() { String host = System.getProperty(