Skip to content

Commit

Permalink
Fix chunked request body handling with HTTPS proxy, close #1571
Browse files Browse the repository at this point in the history
Motivation:

Sending a chunked request body (hence not direct) cause AHC to crash.

Motivation:

Fix SslHandler position that should be before the ChunkedWriteHandler.

Result:

Chunked request works with HTTPS proxy.
  • Loading branch information
slandelle committed Aug 27, 2018
1 parent 4d03ad6 commit a6d1cd2
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
Expand Up @@ -345,7 +345,7 @@ public Future<Channel> updatePipelineForHttpTunneling(ChannelPipeline pipeline,
if (!isSslHandlerConfigured(pipeline)) {
SslHandler sslHandler = createSslHandler(requestUri.getHost(), requestUri.getExplicitPort());
whenHanshaked = sslHandler.handshakeFuture();
pipeline.addBefore(AHC_HTTP_HANDLER, SSL_HANDLER, sslHandler);
pipeline.addBefore(CHUNKED_WRITER_HANDLER, SSL_HANDLER, sslHandler);
}
pipeline.addAfter(SSL_HANDLER, HTTP_CLIENT_CODEC, newHttpClientCodec());

Expand Down Expand Up @@ -380,10 +380,11 @@ public SslHandler addSslHandler(ChannelPipeline pipeline, Uri uri, String virtua
}

SslHandler sslHandler = createSslHandler(peerHost, peerPort);
if (hasSocksProxyHandler)
if (hasSocksProxyHandler) {
pipeline.addAfter(SOCKS_HANDLER, SSL_HANDLER, sslHandler);
else
} else {
pipeline.addFirst(SSL_HANDLER, sslHandler);
}
return sslHandler;
}

Expand Down
15 changes: 15 additions & 0 deletions client/src/test/java/org/asynchttpclient/proxy/HttpsProxyTest.java
Expand Up @@ -13,6 +13,7 @@
package org.asynchttpclient.proxy;

import org.asynchttpclient.*;
import org.asynchttpclient.request.body.generator.ByteArrayBodyGenerator;
import org.asynchttpclient.test.EchoHandler;
import org.eclipse.jetty.proxy.ConnectHandler;
import org.eclipse.jetty.server.Server;
Expand All @@ -23,6 +24,7 @@
import org.testng.annotations.Test;

import static org.asynchttpclient.Dsl.*;
import static org.asynchttpclient.test.TestUtils.LARGE_IMAGE_BYTES;
import static org.asynchttpclient.test.TestUtils.addHttpConnector;
import static org.asynchttpclient.test.TestUtils.addHttpsConnector;
import static org.testng.Assert.assertEquals;
Expand Down Expand Up @@ -84,6 +86,19 @@ public void testConfigProxy() throws Exception {
}
}

@Test
public void testNoDirectRequestBodyWithProxy() throws Exception {
AsyncHttpClientConfig config = config()
.setFollowRedirect(true)
.setProxyServer(proxyServer("localhost", port1).build())
.setUseInsecureTrustManager(true)
.build();
try (AsyncHttpClient asyncHttpClient = asyncHttpClient(config)) {
Response r = asyncHttpClient.executeRequest(post(getTargetUrl2()).setBody(new ByteArrayBodyGenerator(LARGE_IMAGE_BYTES))).get();
assertEquals(r.getStatusCode(), 200);
}
}

@Test
public void testPooledConnectionsWithProxy() throws Exception {

Expand Down

0 comments on commit a6d1cd2

Please sign in to comment.