Skip to content

Commit

Permalink
Update DatastoreOptions.httpRequestInitializer to set User-Agent (#1282)
Browse files Browse the repository at this point in the history
  • Loading branch information
mziccard authored and aozarov committed Sep 26, 2016
1 parent f50a31f commit 32e8f8d
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 32e8f8d

Please sign in to comment.