summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/http/HttpConnection.java80
-rw-r--r--luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/http/HttpURLConnectionImpl.java8
-rw-r--r--luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/https/HttpsURLConnectionImpl.java36
-rw-r--r--luni/src/test/java/libcore/java/net/URLConnectionTest.java8
4 files changed, 78 insertions, 54 deletions
diff --git a/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/http/HttpConnection.java b/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/http/HttpConnection.java
index e0a425b..6db7396 100644
--- a/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/http/HttpConnection.java
+++ b/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/http/HttpConnection.java
@@ -167,29 +167,33 @@ public final class HttpConnection {
* TLS extensions and SSL deflate compression. If false, use
* an SSL3 only fallback mode without compression.
*/
- public SSLSocket getSecureSocket(SSLSocketFactory sslSocketFactory,
+ public SSLSocket setupSecureSocket(SSLSocketFactory sslSocketFactory,
HostnameVerifier hostnameVerifier,
boolean tlsTolerant) throws IOException {
- if (sslSocket == null) {
- // create the wrapper over connected socket
- SSLSocket unverifiedSocket = (SSLSocket) sslSocketFactory.createSocket(socket,
- address.uri.getHost(), address.uri.getEffectivePort(), true /* autoClose */);
- // tlsTolerant mimics Chrome's behavior
- if (tlsTolerant && unverifiedSocket instanceof OpenSSLSocketImpl) {
- OpenSSLSocketImpl openSslSocket = (OpenSSLSocketImpl) unverifiedSocket;
- openSslSocket.setEnabledCompressionMethods(new String[] { "ZLIB"});
- openSslSocket.setUseSessionTickets(true);
- openSslSocket.setHostname(address.hostName);
- // use SSLSocketFactory default enabled protocols
- } else {
- unverifiedSocket.setEnabledProtocols(new String [] { "SSLv3" });
- }
- if (!hostnameVerifier.verify(address.uri.getHost(), unverifiedSocket.getSession())) {
- throw new IOException("Hostname '" + address.uri.getHost() + "' was not verified");
- }
- sslSocket = unverifiedSocket;
+ // create the wrapper over connected socket
+ SSLSocket unverifiedSocket = (SSLSocket) sslSocketFactory.createSocket(socket,
+ address.uri.getHost(), address.uri.getEffectivePort(), true /* autoClose */);
+ // tlsTolerant mimics Chrome's behavior
+ if (tlsTolerant && unverifiedSocket instanceof OpenSSLSocketImpl) {
+ OpenSSLSocketImpl openSslSocket = (OpenSSLSocketImpl) unverifiedSocket;
+ openSslSocket.setEnabledCompressionMethods(new String[] { "ZLIB"});
+ openSslSocket.setUseSessionTickets(true);
+ openSslSocket.setHostname(address.hostName);
+ // use SSLSocketFactory default enabled protocols
+ } else {
+ unverifiedSocket.setEnabledProtocols(new String [] { "SSLv3" });
+ }
+ if (!hostnameVerifier.verify(address.uri.getHost(), unverifiedSocket.getSession())) {
+ throw new IOException("Hostname '" + address.uri.getHost() + "' was not verified");
}
+ sslSocket = unverifiedSocket;
+ return sslSocket;
+ }
+ /**
+ * Return an {@code SSLSocket} if already connected, otherwise null.
+ */
+ public SSLSocket getSecureSocketIfConnected() {
return sslSocket;
}
@@ -266,8 +270,8 @@ public final class HttpConnection {
SocketAddress proxyAddress = proxy.address();
if (!(proxyAddress instanceof InetSocketAddress)) {
- throw new IllegalArgumentException("Proxy.address() is not an InetSocketAddress: " +
- proxyAddress.getClass());
+ throw new IllegalArgumentException("Proxy.address() is not an InetSocketAddress: "
+ + proxyAddress.getClass());
}
InetSocketAddress proxySocketAddress = (InetSocketAddress) proxyAddress;
this.hostName = proxySocketAddress.getHostName();
@@ -275,24 +279,24 @@ public final class HttpConnection {
}
@Override public boolean equals(Object other) {
- if (other instanceof Address) {
- Address that = (Address) other;
- return Objects.equal(this.proxy, that.proxy)
- && this.uri.getHost().equals(that.uri.getHost())
- && this.uri.getEffectivePort() == that.uri.getEffectivePort()
- && this.requiresTunnel == that.requiresTunnel;
- }
- return false;
- }
+ if (other instanceof Address) {
+ Address that = (Address) other;
+ return Objects.equal(this.proxy, that.proxy)
+ && this.uri.getHost().equals(that.uri.getHost())
+ && this.uri.getEffectivePort() == that.uri.getEffectivePort()
+ && this.requiresTunnel == that.requiresTunnel;
+ }
+ return false;
+ }
- @Override public int hashCode() {
- int result = 17;
- result = 31 * result + uri.getHost().hashCode();
- result = 31 * result + uri.getEffectivePort();
- result = 31 * result + (proxy != null ? proxy.hashCode() : 0);
- result = 31 * result + (requiresTunnel ? 1 : 0);
- return result;
- }
+ @Override public int hashCode() {
+ int result = 17;
+ result = 31 * result + uri.getHost().hashCode();
+ result = 31 * result + uri.getEffectivePort();
+ result = 31 * result + (proxy != null ? proxy.hashCode() : 0);
+ result = 31 * result + (requiresTunnel ? 1 : 0);
+ return result;
+ }
public HttpConnection connect(int connectTimeout) throws IOException {
return new HttpConnection(this, connectTimeout);
diff --git a/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/http/HttpURLConnectionImpl.java b/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/http/HttpURLConnectionImpl.java
index dffe6e6..d694a42 100644
--- a/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/http/HttpURLConnectionImpl.java
+++ b/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/http/HttpURLConnectionImpl.java
@@ -383,6 +383,7 @@ public class HttpURLConnectionImpl extends HttpURLConnection {
* code, message, headers and body.
*/
protected void discardIntermediateResponse() throws IOException {
+ boolean oldIntermediateResponse = intermediateResponse;
intermediateResponse = true;
try {
if (responseBodyIn != null) {
@@ -399,7 +400,7 @@ public class HttpURLConnectionImpl extends HttpURLConnection {
responseMessage = null;
cacheRequest = null;
} finally {
- intermediateResponse = false;
+ intermediateResponse = oldIntermediateResponse;
}
}
@@ -496,7 +497,8 @@ public class HttpURLConnectionImpl extends HttpURLConnection {
@Override
public Map<String, List<String>> getRequestProperties() {
if (connected) {
- throw new IllegalStateException("Cannot access request header fields after connection is set");
+ throw new IllegalStateException(
+ "Cannot access request header fields after connection is set");
}
return requestHeader.getFieldMap();
}
@@ -614,7 +616,7 @@ public class HttpURLConnectionImpl extends HttpURLConnection {
connect();
if (socketOut == null) {
- // TODO: what should we do if a cached response exists?
+ // TODO: what should we do if a cached response exists?
throw new IOException("No socket to write to; was a POST cached?");
}
diff --git a/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/https/HttpsURLConnectionImpl.java b/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/https/HttpsURLConnectionImpl.java
index c7210f5..9db8f96 100644
--- a/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/https/HttpsURLConnectionImpl.java
+++ b/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/https/HttpsURLConnectionImpl.java
@@ -38,10 +38,19 @@ import org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionI
*/
public class HttpsURLConnectionImpl extends HttpsURLConnection {
- // Https engine to be wrapped
+ /**
+ * HttpsEngine that allows reuse of HttpURLConnectionImpl
+ */
private final HttpsEngine httpsEngine;
- // SSLSocket to be used for connection
+ /**
+ * Local stash of HttpsEngine.connection.sslSocket for answering
+ * queries such as getCipherSuite even after
+ * httpsEngine.Connection has been recycled. It's presense is also
+ * used to tell if the HttpsURLConnection is considered connected,
+ * as opposed to the connected field of URLConnection or the a
+ * non-null connect in HttpURLConnectionImpl
+ */
private SSLSocket sslSocket;
protected HttpsURLConnectionImpl(URL url, int port) {
@@ -366,6 +375,7 @@ public class HttpsURLConnectionImpl extends HttpsURLConnection {
makeSslConnection(true);
} catch (IOException e) {
releaseSocket(false);
+ sslSocket = null;
makeSslConnection(false);
}
}
@@ -378,8 +388,24 @@ public class HttpsURLConnectionImpl extends HttpsURLConnection {
* an SSL3 only fallback mode without compression.
*/
private void makeSslConnection(boolean tlsTolerant) throws IOException {
+
super.makeConnection();
+ // if super.makeConnection returned a connection from the
+ // pool, sslSocket needs to be initialized here. If it is
+ // a new connection, it will be initialized by
+ // getSecureSocket below.
+ sslSocket = connection.getSecureSocketIfConnected();
+
+ // we already have an SSL connection,
+ if (sslSocket != null) {
+ // ensure requestOut etc are reinitialized. they will
+ // not have been set by super.makeSslConnection's call
+ // to setUpTransportIO because sslSocket was not yet set.
+ setUpTransportIO(connection);
+ return;
+ }
+
// make SSL Tunnel
if (requiresTunnel()) {
String originalMethod = method;
@@ -394,9 +420,9 @@ public class HttpsURLConnectionImpl extends HttpsURLConnection {
}
}
- sslSocket = connection.getSecureSocket(getSSLSocketFactory(),
- getHostnameVerifier(),
- tlsTolerant);
+ sslSocket = connection.setupSecureSocket(getSSLSocketFactory(),
+ getHostnameVerifier(),
+ tlsTolerant);
setUpTransportIO(connection);
}
diff --git a/luni/src/test/java/libcore/java/net/URLConnectionTest.java b/luni/src/test/java/libcore/java/net/URLConnectionTest.java
index cd0dc7b..10128b8 100644
--- a/luni/src/test/java/libcore/java/net/URLConnectionTest.java
+++ b/luni/src/test/java/libcore/java/net/URLConnectionTest.java
@@ -544,14 +544,6 @@ public class URLConnectionTest extends junit.framework.TestCase {
testConnectViaHttpProxyToHttps(ProxyConfig.CREATE_ARG);
}
- /**
- * We weren't honoring all of the appropriate proxy system properties when
- * connecting via HTTPS. http://b/3097518
- */
- public void testConnectViaHttpProxyToHttpsUsingProxySystemProperty() throws Exception {
- testConnectViaHttpProxyToHttps(ProxyConfig.PROXY_SYSTEM_PROPERTY);
- }
-
public void testConnectViaHttpProxyToHttpsUsingHttpsProxySystemProperty() throws Exception {
testConnectViaHttpProxyToHttps(ProxyConfig.HTTPS_PROXY_SYSTEM_PROPERTY);
}