Skip to content

Commit

Permalink
Update DatastoreOptions.httpRequestInitializer to set User-Agent
Browse files Browse the repository at this point in the history
  • Loading branch information
mziccard committed Sep 26, 2016
1 parent 6743dc0 commit 8f42224
Showing 1 changed file with 15 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,16 @@

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;
import com.google.cloud.datastore.spi.DefaultDatastoreRpc;
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;
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit 8f42224

Please sign in to comment.