okhttp: generate user agent once for whole transport

This commit is contained in:
Carl Mastrangelo 2016-05-25 15:45:36 -07:00
parent f172170649
commit ca8e166591
3 changed files with 4 additions and 7 deletions

View File

@ -46,8 +46,6 @@ import okio.ByteString;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import javax.annotation.Nullable;
/** /**
* Constants for request/response headers. * Constants for request/response headers.
*/ */
@ -65,7 +63,7 @@ public class Headers {
* application thread context. * application thread context.
*/ */
public static List<Header> createRequestHeaders(Metadata headers, String defaultPath, public static List<Header> createRequestHeaders(Metadata headers, String defaultPath,
String authority, @Nullable String applicationUserAgent) { String authority, String userAgent) {
Preconditions.checkNotNull(headers, "headers"); Preconditions.checkNotNull(headers, "headers");
Preconditions.checkNotNull(defaultPath, "defaultPath"); Preconditions.checkNotNull(defaultPath, "defaultPath");
Preconditions.checkNotNull(authority, "authority"); Preconditions.checkNotNull(authority, "authority");
@ -81,7 +79,6 @@ public class Headers {
String path = defaultPath; String path = defaultPath;
okhttpHeaders.add(new Header(Header.TARGET_PATH, path)); okhttpHeaders.add(new Header(Header.TARGET_PATH, path));
String userAgent = GrpcUtil.getGrpcUserAgent("okhttp", applicationUserAgent);
okhttpHeaders.add(new Header(GrpcUtil.USER_AGENT_KEY.name(), userAgent)); okhttpHeaders.add(new Header(GrpcUtil.USER_AGENT_KEY.name(), userAgent));
// All non-pseudo headers must come after pseudo headers. // All non-pseudo headers must come after pseudo headers.

View File

@ -96,7 +96,7 @@ class OkHttpClientStream extends Http2ClientStream {
Object lock, Object lock,
int maxMessageSize, int maxMessageSize,
String authority, String authority,
@Nullable String userAgent) { String userAgent) {
super(new OkHttpWritableBufferAllocator(), maxMessageSize); super(new OkHttpWritableBufferAllocator(), maxMessageSize);
this.method = method; this.method = method;
this.headers = headers; this.headers = headers;

View File

@ -183,7 +183,7 @@ class OkHttpClientTransport implements ManagedClientTransport {
this.sslSocketFactory = sslSocketFactory; this.sslSocketFactory = sslSocketFactory;
this.connectionSpec = Preconditions.checkNotNull(connectionSpec, "connectionSpec"); this.connectionSpec = Preconditions.checkNotNull(connectionSpec, "connectionSpec");
this.ticker = Ticker.systemTicker(); this.ticker = Ticker.systemTicker();
this.userAgent = userAgent; this.userAgent = GrpcUtil.getGrpcUserAgent("okhttp", userAgent);
} }
/** /**
@ -197,7 +197,7 @@ class OkHttpClientTransport implements ManagedClientTransport {
address = null; address = null;
this.maxMessageSize = maxMessageSize; this.maxMessageSize = maxMessageSize;
defaultAuthority = "notarealauthority:80"; defaultAuthority = "notarealauthority:80";
this.userAgent = userAgent; this.userAgent = GrpcUtil.getGrpcUserAgent("okhttp", userAgent);
this.executor = Preconditions.checkNotNull(executor); this.executor = Preconditions.checkNotNull(executor);
serializingExecutor = new SerializingExecutor(executor); serializingExecutor = new SerializingExecutor(executor);
this.testFrameReader = Preconditions.checkNotNull(frameReader); this.testFrameReader = Preconditions.checkNotNull(frameReader);