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

okhttp: update okhttp and okio dependencies #5248

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -204,8 +204,8 @@ subprojects {
google_api_protos: 'com.google.api.grpc:proto-google-common-protos:1.12.0',
google_auth_credentials: "com.google.auth:google-auth-library-credentials:${googleauthVersion}",
google_auth_oauth2_http: "com.google.auth:google-auth-library-oauth2-http:${googleauthVersion}",
okhttp: 'com.squareup.okhttp:okhttp:2.5.0',
okio: 'com.squareup.okio:okio:1.13.0',
okhttp: 'com.squareup.okhttp3:okhttp:3.12.1',
okio: 'com.squareup.okio:okio:2.1.0',
opencensus_api: "io.opencensus:opencensus-api:${opencensusVersion}",
opencensus_contrib_grpc_metrics: "io.opencensus:opencensus-contrib-grpc-metrics:${opencensusVersion}",
opencensus_impl: "io.opencensus:opencensus-impl:${opencensusVersion}",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import static org.junit.Assert.assertTrue;

import com.google.common.base.Throwables;
import com.squareup.okhttp.ConnectionSpec;
import io.grpc.ManagedChannel;
import io.grpc.internal.AbstractServerImplBuilder;
import io.grpc.internal.GrpcUtil;
Expand All @@ -42,6 +41,7 @@
import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.SSLPeerUnverifiedException;
import javax.net.ssl.SSLSession;
import okhttp3.ConnectionSpec;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
Expand Down
2 changes: 1 addition & 1 deletion okhttp/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ project.sourceSets {
checkstyleMain.exclude '**/io/grpc/okhttp/internal/**'

javadoc.exclude 'io/grpc/okhttp/internal/**'
javadoc.options.links 'http://square.github.io/okhttp/2.x/okhttp/'
javadoc.options.links 'http://square.github.io/okhttp/3.x/okhttp/'
24 changes: 12 additions & 12 deletions okhttp/src/main/java/io/grpc/okhttp/OkHttpChannelBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -90,19 +90,19 @@ private enum NegotiationType {
* @deprecated Deemed of little benefit and users weren't using it. Just define one yourself
*/
@Deprecated
public static final com.squareup.okhttp.ConnectionSpec DEFAULT_CONNECTION_SPEC =
new com.squareup.okhttp.ConnectionSpec.Builder(com.squareup.okhttp.ConnectionSpec.MODERN_TLS)
public static final okhttp3.ConnectionSpec DEFAULT_CONNECTION_SPEC =
new okhttp3.ConnectionSpec.Builder(okhttp3.ConnectionSpec.MODERN_TLS)
.cipherSuites(
// The following items should be sync with Netty's Http2SecurityUtil.CIPHERS.
com.squareup.okhttp.CipherSuite.TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384,
com.squareup.okhttp.CipherSuite.TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
com.squareup.okhttp.CipherSuite.TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,
com.squareup.okhttp.CipherSuite.TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
com.squareup.okhttp.CipherSuite.TLS_DHE_RSA_WITH_AES_128_GCM_SHA256,
com.squareup.okhttp.CipherSuite.TLS_DHE_DSS_WITH_AES_128_GCM_SHA256,
com.squareup.okhttp.CipherSuite.TLS_DHE_RSA_WITH_AES_256_GCM_SHA384,
com.squareup.okhttp.CipherSuite.TLS_DHE_DSS_WITH_AES_256_GCM_SHA384)
.tlsVersions(com.squareup.okhttp.TlsVersion.TLS_1_2)
okhttp3.CipherSuite.TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384,
okhttp3.CipherSuite.TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
okhttp3.CipherSuite.TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,
okhttp3.CipherSuite.TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
okhttp3.CipherSuite.TLS_DHE_RSA_WITH_AES_128_GCM_SHA256,
okhttp3.CipherSuite.TLS_DHE_DSS_WITH_AES_128_GCM_SHA256,
okhttp3.CipherSuite.TLS_DHE_RSA_WITH_AES_256_GCM_SHA384,
okhttp3.CipherSuite.TLS_DHE_DSS_WITH_AES_256_GCM_SHA384)
.tlsVersions(okhttp3.TlsVersion.TLS_1_2)
.supportsTlsExtensions(true)
.build();

Expand Down Expand Up @@ -346,7 +346,7 @@ public final OkHttpChannelBuilder hostnameVerifier(@Nullable HostnameVerifier ho
* If {@code connectionSpec} is not with TLS
*/
public final OkHttpChannelBuilder connectionSpec(
com.squareup.okhttp.ConnectionSpec connectionSpec) {
okhttp3.ConnectionSpec connectionSpec) {
Preconditions.checkArgument(connectionSpec.isTls(), "plaintext ConnectionSpec is not accepted");
this.connectionSpec = Utils.convertSpec(connectionSpec);
return this;
Expand Down
12 changes: 6 additions & 6 deletions okhttp/src/main/java/io/grpc/okhttp/OkHttpClientTransport.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,6 @@
import com.google.common.base.Supplier;
import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.SettableFuture;
import com.squareup.okhttp.Credentials;
import com.squareup.okhttp.HttpUrl;
import com.squareup.okhttp.Request;
import com.squareup.okhttp.internal.http.StatusLine;
import io.grpc.Attributes;
import io.grpc.CallOptions;
import io.grpc.Grpc;
Expand Down Expand Up @@ -90,6 +86,10 @@
import javax.net.ssl.SSLSession;
import javax.net.ssl.SSLSocket;
import javax.net.ssl.SSLSocketFactory;
import okhttp3.Credentials;
import okhttp3.HttpUrl;
import okhttp3.Request;
import okhttp3.internal.http.StatusLine;
import okio.Buffer;
import okio.BufferedSink;
import okio.BufferedSource;
Expand Down Expand Up @@ -585,7 +585,7 @@ private Socket createHttpProxySocket(InetSocketAddress address, InetSocketAddres

// Prepare headers and request method line
Request proxyRequest = createHttpProxyRequest(address, proxyUsername, proxyPassword);
HttpUrl url = proxyRequest.httpUrl();
HttpUrl url = proxyRequest.url();
String requestLine = String.format("CONNECT %s:%d HTTP/1.1", url.host(), url.port());

// Write request to socket
Expand Down Expand Up @@ -1063,7 +1063,7 @@ public void data(boolean inFinished, int streamId, BufferedSource in, int length
in.require(length);

Buffer buf = new Buffer();
buf.write(in.buffer(), length);
buf.write(in.getBuffer(), length);
synchronized (lock) {
stream.transportState().transportDataReceived(buf, inFinished);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,11 @@ public int readableBytes() {

@Override
public int readUnsignedByte() {
return buffer.readByte() & 0x000000FF;
try {
return buffer.readByte() & 0x000000FF;
} catch (EOFException e) {
throw new IndexOutOfBoundsException(e.getMessage());
}
}

@Override
Expand Down
10 changes: 5 additions & 5 deletions okhttp/src/main/java/io/grpc/okhttp/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,25 +64,25 @@ private static byte[][] convertHeadersToArray(List<Header> http2Headers) {
}

/**
* Converts an instance of {@link com.squareup.okhttp.ConnectionSpec} for a secure connection into
* Converts an instance of {@link okhttp3.ConnectionSpec} for a secure connection into
* that of {@link ConnectionSpec} in the current package.
*
* @throws IllegalArgumentException
* If {@code spec} is not with TLS
*/
static ConnectionSpec convertSpec(com.squareup.okhttp.ConnectionSpec spec) {
static ConnectionSpec convertSpec(okhttp3.ConnectionSpec spec) {
Preconditions.checkArgument(spec.isTls(), "plaintext ConnectionSpec is not accepted");

List<com.squareup.okhttp.TlsVersion> tlsVersionList = spec.tlsVersions();
List<okhttp3.TlsVersion> tlsVersionList = spec.tlsVersions();
String[] tlsVersions = new String[tlsVersionList.size()];
for (int i = 0; i < tlsVersions.length; i++) {
tlsVersions[i] = tlsVersionList.get(i).javaName();
}

List<com.squareup.okhttp.CipherSuite> cipherSuiteList = spec.cipherSuites();
List<okhttp3.CipherSuite> cipherSuiteList = spec.cipherSuites();
CipherSuite[] cipherSuites = new CipherSuite[cipherSuiteList.size()];
for (int i = 0; i < cipherSuites.length; i++) {
cipherSuites[i] = CipherSuite.valueOf(cipherSuiteList.get(i).name());
cipherSuites[i] = CipherSuite.forJavaName(cipherSuiteList.get(i).javaName());
}

return new ConnectionSpec.Builder(spec.isTls())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;

import com.squareup.okhttp.ConnectionSpec;
import io.grpc.NameResolver;
import io.grpc.internal.ClientTransportFactory;
import io.grpc.internal.FakeClock;
import io.grpc.internal.GrpcUtil;
import io.grpc.internal.SharedResourceHolder;
import java.net.InetSocketAddress;
import java.util.concurrent.ScheduledExecutorService;
import okhttp3.ConnectionSpec;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
Expand Down
14 changes: 8 additions & 6 deletions okhttp/src/test/java/io/grpc/okhttp/UtilsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,33 +42,35 @@ public class UtilsTest {

@Test
public void convertSpecRejectsPlaintext() {
com.squareup.okhttp.ConnectionSpec plaintext = com.squareup.okhttp.ConnectionSpec.CLEARTEXT;
okhttp3.ConnectionSpec plaintext = okhttp3.ConnectionSpec.CLEARTEXT;
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage("plaintext ConnectionSpec is not accepted");
Utils.convertSpec(plaintext);
}

@Test
public void convertSpecKeepsAllData() {
com.squareup.okhttp.ConnectionSpec squareSpec = com.squareup.okhttp.ConnectionSpec.MODERN_TLS;
okhttp3.ConnectionSpec squareSpec = okhttp3.ConnectionSpec.MODERN_TLS;
ConnectionSpec spec = Utils.convertSpec(squareSpec);

List<com.squareup.okhttp.TlsVersion> squareTlsVersions = squareSpec.tlsVersions();
List<okhttp3.TlsVersion> squareTlsVersions = squareSpec.tlsVersions();
List<TlsVersion> tlsVersions = spec.tlsVersions();
int versionsSize = squareTlsVersions.size();
List<com.squareup.okhttp.CipherSuite> squareCipherSuites = squareSpec.cipherSuites();
List<okhttp3.CipherSuite> squareCipherSuites = squareSpec.cipherSuites();
List<CipherSuite> cipherSuites = spec.cipherSuites();
int cipherSuitesSize = squareCipherSuites.size();

assertTrue(spec.isTls());
assertTrue(spec.supportsTlsExtensions());
assertEquals(versionsSize, tlsVersions.size());
for (int i = 0; i < versionsSize; i++) {
assertEquals(TlsVersion.forJavaName(squareTlsVersions.get(i).javaName()), tlsVersions.get(i));
assertEquals(TlsVersion.forJavaName(
squareTlsVersions.get(i).javaName()), tlsVersions.get(i));
}
assertEquals(cipherSuitesSize, cipherSuites.size());
for (int i = 0; i < cipherSuitesSize; i++) {
assertEquals(CipherSuite.forJavaName(squareCipherSuites.get(i).name()), cipherSuites.get(i));
assertEquals(CipherSuite.forJavaName(
squareCipherSuites.get(i).javaName()), cipherSuites.get(i));
}
}

Expand Down