Skip to content

Commit d5a0f20

Browse files
committed
Honor proxy credentials when setting a SOCKS proxy, close AsyncHttpClient#1509
Motivation: We don’t currently honor proxy’s Realm when setting a SOCKS proxy. Modifications: Pass username and password when creating a Socks(4|5)ProxyHandler. Result: Creds honored on SOCKS proxies
1 parent 4d5c0eb commit d5a0f20

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
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
@@ -410,14 +410,17 @@ public void handlerAdded(ChannelHandlerContext ctx) throws Exception {
410410
@Override
411411
protected void initChannel(Channel channel) throws Exception {
412412
InetSocketAddress proxyAddress = new InetSocketAddress(whenProxyAddress.get(), proxy.getPort());
413+
Realm realm = proxy.getRealm();
414+
String username = realm != null ? realm.getPrincipal() : null;
415+
String password = realm != null ? realm.getPassword() : null;
413416
ProxyHandler socksProxyHandler;
414417
switch (proxy.getProxyType()) {
415418
case SOCKS_V4:
416-
socksProxyHandler = new Socks4ProxyHandler(proxyAddress);
419+
socksProxyHandler = new Socks4ProxyHandler(proxyAddress, username);
417420
break;
418421

419422
case SOCKS_V5:
420-
socksProxyHandler = new Socks5ProxyHandler(proxyAddress);
423+
socksProxyHandler = new Socks5ProxyHandler(proxyAddress, username, password);
421424
break;
422425

423426
default:

0 commit comments

Comments
 (0)