Revert "Temporary workaround for whatsapp issues."
WhatsApp have address this issue so we no longer need the workaround.
This reverts commit cdf3c4bc9e853c99d82d4c1dfc907ef2694f2ed7.
Bug: 27353040
Change-Id: I41f68860bf04adcb231b316b0eaa3f32ba294ff7
diff --git a/okhttp-tests/src/test/java/com/squareup/okhttp/InterceptorTest.java b/okhttp-tests/src/test/java/com/squareup/okhttp/InterceptorTest.java
index d8454ac..054343c 100644
--- a/okhttp-tests/src/test/java/com/squareup/okhttp/InterceptorTest.java
+++ b/okhttp-tests/src/test/java/com/squareup/okhttp/InterceptorTest.java
@@ -135,7 +135,7 @@
Interceptor interceptor = new Interceptor() {
@Override public Response intercept(Chain chain) throws IOException {
Address address = chain.connection().getRoute().getAddress();
- String sameHost = address.getRfc2732Host();
+ String sameHost = address.getUriHost();
int differentPort = address.getUriPort() + 1;
return chain.proceed(chain.request().newBuilder()
.url(HttpUrl.parse("http://" + sameHost + ":" + differentPort + "/"))
diff --git a/okhttp/src/main/java/com/squareup/okhttp/Address.java b/okhttp/src/main/java/com/squareup/okhttp/Address.java
index cd3687b..6f6ce08 100644
--- a/okhttp/src/main/java/com/squareup/okhttp/Address.java
+++ b/okhttp/src/main/java/com/squareup/okhttp/Address.java
@@ -71,7 +71,7 @@
}
/** Returns the hostname of the origin server. */
- public String getRfc2732Host() {
+ public String getUriHost() {
return uriHost;
}
diff --git a/okhttp/src/main/java/com/squareup/okhttp/Connection.java b/okhttp/src/main/java/com/squareup/okhttp/Connection.java
index a778747..2a3614e 100644
--- a/okhttp/src/main/java/com/squareup/okhttp/Connection.java
+++ b/okhttp/src/main/java/com/squareup/okhttp/Connection.java
@@ -222,13 +222,13 @@
try {
// Create the wrapper over the connected socket.
sslSocket = (SSLSocket) sslSocketFactory.createSocket(
- socket, address.getRfc2732Host(), address.getUriPort(), true /* autoClose */);
+ socket, address.getUriHost(), address.getUriPort(), true /* autoClose */);
// Configure the socket's ciphers, TLS versions, and extensions.
ConnectionSpec connectionSpec = connectionSpecSelector.configureSecureSocket(sslSocket);
if (connectionSpec.supportsTlsExtensions()) {
Platform.get().configureTlsExtensions(
- sslSocket, address.getRfc2732Host(), address.getProtocols());
+ sslSocket, address.getUriHost(), address.getProtocols());
}
// Force handshake. This can throw!
@@ -236,16 +236,16 @@
Handshake unverifiedHandshake = Handshake.get(sslSocket.getSession());
// Verify that the socket's certificates are acceptable for the target host.
- if (!address.getHostnameVerifier().verify(address.getRfc2732Host(), sslSocket.getSession())) {
+ if (!address.getHostnameVerifier().verify(address.getUriHost(), sslSocket.getSession())) {
X509Certificate cert = (X509Certificate) unverifiedHandshake.peerCertificates().get(0);
- throw new SSLPeerUnverifiedException("Hostname " + address.getRfc2732Host() + " not verified:"
+ throw new SSLPeerUnverifiedException("Hostname " + address.getUriHost() + " not verified:"
+ "\n certificate: " + CertificatePinner.pin(cert)
+ "\n DN: " + cert.getSubjectDN().getName()
+ "\n subjectAltNames: " + OkHostnameVerifier.allSubjectAltNames(cert));
}
// Check that the certificate pinner is satisfied by the certificates presented.
- address.getCertificatePinner().check(address.getRfc2732Host(),
+ address.getCertificatePinner().check(address.getUriHost(),
unverifiedHandshake.peerCertificates());
// Success! Save the handshake and the ALPN protocol.
@@ -282,7 +282,7 @@
HttpConnection tunnelConnection = new HttpConnection(pool, this, socket);
tunnelConnection.setTimeouts(readTimeout, writeTimeout);
HttpUrl url = tunnelRequest.httpUrl();
- String requestLine = "CONNECT " + url.rfc2732host() + ":" + url.port() + " HTTP/1.1";
+ String requestLine = "CONNECT " + url.host() + ":" + url.port() + " HTTP/1.1";
while (true) {
tunnelConnection.writeRequest(tunnelRequest.headers(), requestLine);
tunnelConnection.flush();
diff --git a/okhttp/src/main/java/com/squareup/okhttp/HttpUrl.java b/okhttp/src/main/java/com/squareup/okhttp/HttpUrl.java
index beabeca..69588ed 100644
--- a/okhttp/src/main/java/com/squareup/okhttp/HttpUrl.java
+++ b/okhttp/src/main/java/com/squareup/okhttp/HttpUrl.java
@@ -402,19 +402,6 @@
}
/**
- * Same as {@link #host} except that literal IPv6 addresses are surrounding by square
- * braces. For example, this method will return {@code [::1]} where {@code host} returns
- * {@code ::1}.
- */
- public String rfc2732host() {
- if (host.indexOf(':') == -1) {
- return host;
- }
-
- return "[" + host + "]";
- }
-
- /**
* Returns the explicitly-specified port if one was provided, or the default port for this URL's
* scheme. For example, this returns 8443 for {@code https://square.com:8443/} and 443 for {@code
* https://square.com/}. The result is in {@code [1..65535]}.
diff --git a/okhttp/src/main/java/com/squareup/okhttp/internal/Util.java b/okhttp/src/main/java/com/squareup/okhttp/internal/Util.java
index 4000fbe..efc26ec 100644
--- a/okhttp/src/main/java/com/squareup/okhttp/internal/Util.java
+++ b/okhttp/src/main/java/com/squareup/okhttp/internal/Util.java
@@ -259,8 +259,8 @@
public static String hostHeader(HttpUrl url) {
// TODO: square braces for IPv6 ?
return url.port() != HttpUrl.defaultPort(url.scheme())
- ? url.rfc2732host() + ":" + url.port()
- : url.rfc2732host();
+ ? url.host() + ":" + url.port()
+ : url.host();
}
/** Returns {@code s} with control characters and non-ASCII characters replaced with '?'. */
diff --git a/okhttp/src/main/java/com/squareup/okhttp/internal/http/AuthenticatorAdapter.java b/okhttp/src/main/java/com/squareup/okhttp/internal/http/AuthenticatorAdapter.java
index a9f9b5a..8d88410 100644
--- a/okhttp/src/main/java/com/squareup/okhttp/internal/http/AuthenticatorAdapter.java
+++ b/okhttp/src/main/java/com/squareup/okhttp/internal/http/AuthenticatorAdapter.java
@@ -43,7 +43,7 @@
if (!"Basic".equalsIgnoreCase(challenge.getScheme())) continue;
PasswordAuthentication auth = java.net.Authenticator.requestPasswordAuthentication(
- url.rfc2732host(), getConnectToInetAddress(proxy, url), url.port(), url.scheme(),
+ url.host(), getConnectToInetAddress(proxy, url), url.port(), url.scheme(),
challenge.getRealm(), challenge.getScheme(), url.url(), RequestorType.SERVER);
if (auth == null) continue;
diff --git a/okhttp/src/main/java/com/squareup/okhttp/internal/http/HttpEngine.java b/okhttp/src/main/java/com/squareup/okhttp/internal/http/HttpEngine.java
index 7286428..70eeaaa 100644
--- a/okhttp/src/main/java/com/squareup/okhttp/internal/http/HttpEngine.java
+++ b/okhttp/src/main/java/com/squareup/okhttp/internal/http/HttpEngine.java
@@ -848,7 +848,7 @@
Address address = connection().getRoute().getAddress();
// Confirm that the interceptor uses the connection we've already prepared.
- if (!request.httpUrl().rfc2732host().equals(address.getRfc2732Host())
+ if (!request.httpUrl().host().equals(address.getUriHost())
|| request.httpUrl().port() != address.getUriPort()) {
throw new IllegalStateException("network interceptor " + caller
+ " must retain the same host and port");
@@ -1135,7 +1135,7 @@
certificatePinner = client.getCertificatePinner();
}
- return new Address(request.httpUrl().rfc2732host(), request.httpUrl().port(),
+ return new Address(request.httpUrl().host(), request.httpUrl().port(),
client.getSocketFactory(), sslSocketFactory, hostnameVerifier, certificatePinner,
client.getAuthenticator(), client.getProxy(), client.getProtocols(),
client.getConnectionSpecs(), client.getProxySelector());
diff --git a/okhttp/src/main/java/com/squareup/okhttp/internal/http/RouteSelector.java b/okhttp/src/main/java/com/squareup/okhttp/internal/http/RouteSelector.java
index b210c56..b16bab3 100644
--- a/okhttp/src/main/java/com/squareup/okhttp/internal/http/RouteSelector.java
+++ b/okhttp/src/main/java/com/squareup/okhttp/internal/http/RouteSelector.java
@@ -149,7 +149,7 @@
/** Returns the next proxy to try. May be PROXY.NO_PROXY but never null. */
private Proxy nextProxy() throws IOException {
if (!hasNextProxy()) {
- throw new SocketException("No route to " + address.getRfc2732Host()
+ throw new SocketException("No route to " + address.getUriHost()
+ "; exhausted proxy configurations: " + proxies);
}
Proxy result = proxies.get(nextProxyIndex++);
@@ -165,7 +165,7 @@
String socketHost;
int socketPort;
if (proxy.type() == Proxy.Type.DIRECT || proxy.type() == Proxy.Type.SOCKS) {
- socketHost = address.getRfc2732Host();
+ socketHost = address.getUriHost();
socketPort = address.getUriPort();
} else {
SocketAddress proxyAddress = proxy.address();
@@ -217,7 +217,7 @@
/** Returns the next socket address to try. */
private InetSocketAddress nextInetSocketAddress() throws IOException {
if (!hasNextInetSocketAddress()) {
- throw new SocketException("No route to " + address.getRfc2732Host()
+ throw new SocketException("No route to " + address.getUriHost()
+ "; exhausted inet socket addresses: " + inetSocketAddresses);
}
return inetSocketAddresses.get(nextInetSocketAddressIndex++);