Skip to content

Commit 050471d

Browse files
userslandelle
authored andcommitted
Make socks proxy work with https, fix AsyncHttpClient#1507
Motivation: All requests to HTTPS URLs via a SOCKS proxy fail with ClosedChannelException due to SslHandler is added to the netty channel pipeline before Socks4ProxyHandler/Socks5ProxyHandler. Modifications: Make sure SslHandler is added into the channel pipeline after Socks4ProxyHandler/Socks5ProxyHandler. Result: Socks proxy works with HTTPS.
1 parent a1d06f7 commit 050471d

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

client/src/main/java/org/asynchttpclient/netty/channel/ChannelManager.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ public void updatePipelineForHttpTunneling(ChannelPipeline pipeline, Uri request
359359
}
360360
}
361361

362-
public SslHandler addSslHandler(ChannelPipeline pipeline, Uri uri, String virtualHost) {
362+
public SslHandler addSslHandler(ChannelPipeline pipeline, Uri uri, String virtualHost, boolean hasSocksProxyHandler) {
363363
String peerHost;
364364
int peerPort;
365365

@@ -379,7 +379,10 @@ public SslHandler addSslHandler(ChannelPipeline pipeline, Uri uri, String virtua
379379
}
380380

381381
SslHandler sslHandler = createSslHandler(peerHost, peerPort);
382-
pipeline.addFirst(ChannelManager.SSL_HANDLER, sslHandler);
382+
if (hasSocksProxyHandler)
383+
pipeline.addAfter(ChannelManager.SOCKS_HANDLER, ChannelManager.SSL_HANDLER, sslHandler);
384+
else
385+
pipeline.addFirst(ChannelManager.SSL_HANDLER, sslHandler);
383386
return sslHandler;
384387
}
385388

client/src/main/java/org/asynchttpclient/netty/channel/NettyConnectListener.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ public void onSuccess(Channel channel, InetSocketAddress remoteAddress) {
112112
if ((proxyServer == null || proxyServer.getProxyType().isSocks()) && uri.isSecured()) {
113113
SslHandler sslHandler;
114114
try {
115-
sslHandler = channelManager.addSslHandler(channel.pipeline(), uri, request.getVirtualHost());
115+
sslHandler = channelManager.addSslHandler(channel.pipeline(), uri, request.getVirtualHost(), proxyServer != null);
116116
} catch (Exception sslError) {
117117
onFailure(channel, sslError);
118118
return;

0 commit comments

Comments
 (0)