Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update DatastoreOptions.httpRequestInitializer to set User-Agent #1282

Merged
merged 1 commit into from
Sep 26, 2016
Merged
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 @@ -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