1
0
mirror of https://github.com/square/okhttp.git synced 2026-01-27 04:22:07 +03:00

Merge pull request #30 from square/jwilson/tunnelconnect

Fix a bug in tunnel construction and 'Connection: close' headers.
This commit is contained in:
Jake Wharton
2012-09-20 13:54:26 -07:00
2 changed files with 29 additions and 3 deletions

View File

@@ -211,10 +211,16 @@ final class HttpTransport implements Transport {
return false;
}
// If the headers specify that the connection shouldn't be reused, don't reuse it.
// If the request specified that the connection shouldn't be reused,
// don't reuse it. This advice doesn't apply to CONNECT requests because
// the "Connection: close" header goes the origin server, not the proxy.
if (httpEngine.requestHeaders.hasConnectionClose()
|| (httpEngine.responseHeaders != null
&& httpEngine.responseHeaders.hasConnectionClose())) {
&& httpEngine.method != HttpEngine.CONNECT) {
return false;
}
// If the response specified that the connection shouldn't be reused, don't reuse it.
if (httpEngine.responseHeaders != null && httpEngine.responseHeaders.hasConnectionClose()) {
return false;
}

View File

@@ -748,6 +748,26 @@ public final class URLConnectionTest extends TestCase {
assertContainsNoneMatching(get.getHeaders(), "Proxy\\-Authorization.*");
}
// Don't disconnect after building a tunnel with CONNECT
// http://code.google.com/p/android/issues/detail?id=37221
public void testProxyWithConnectionClose() throws IOException {
server.useHttps(sslContext.getSocketFactory(), true);
server.enqueue(new MockResponse()
.setSocketPolicy(SocketPolicy.UPGRADE_TO_SSL_AT_END)
.clearHeaders());
server.enqueue(new MockResponse().setBody("this response comes via a proxy"));
server.play();
URL url = new URL("https://android.com/foo");
OkHttpsConnection connection = (OkHttpsConnection) openConnection(
url, server.toProxyAddress());
connection.setRequestProperty("Connection", "close");
connection.setSSLSocketFactory(sslContext.getSocketFactory());
connection.setHostnameVerifier(new RecordingHostnameVerifier());
assertContent("this response comes via a proxy", connection);
}
public void testDisconnectedConnection() throws IOException {
server.enqueue(new MockResponse().setBody("ABCDEFGHIJKLMNOPQR"));
server.play();