28
28
import io .netty .handler .codec .http .websocketx .extensions .compression .WebSocketClientCompressionHandler ;
29
29
import io .netty .handler .logging .LogLevel ;
30
30
import io .netty .handler .logging .LoggingHandler ;
31
+ import io .netty .handler .proxy .ProxyHandler ;
31
32
import io .netty .handler .proxy .Socks4ProxyHandler ;
32
33
import io .netty .handler .proxy .Socks5ProxyHandler ;
33
34
import io .netty .handler .ssl .SslHandler ;
@@ -380,9 +381,9 @@ public SslHandler addSslHandler(ChannelPipeline pipeline, Uri uri, String virtua
380
381
381
382
SslHandler sslHandler = createSslHandler (peerHost , peerPort );
382
383
if (hasSocksProxyHandler )
383
- pipeline .addAfter (ChannelManager . SOCKS_HANDLER , ChannelManager . SSL_HANDLER , sslHandler );
384
+ pipeline .addAfter (SOCKS_HANDLER , SSL_HANDLER , sslHandler );
384
385
else
385
- pipeline .addFirst (ChannelManager . SSL_HANDLER , sslHandler );
386
+ pipeline .addFirst (SSL_HANDLER , sslHandler );
386
387
return sslHandler ;
387
388
}
388
389
@@ -409,18 +410,20 @@ public void handlerAdded(ChannelHandlerContext ctx) throws Exception {
409
410
@ Override
410
411
protected void initChannel (Channel channel ) throws Exception {
411
412
InetSocketAddress proxyAddress = new InetSocketAddress (whenProxyAddress .get (), proxy .getPort ());
413
+ ProxyHandler socksProxyHandler ;
412
414
switch (proxy .getProxyType ()) {
413
415
case SOCKS_V4 :
414
- channel . pipeline (). addFirst ( SOCKS_HANDLER , new Socks4ProxyHandler (proxyAddress ) );
416
+ socksProxyHandler = new Socks4ProxyHandler (proxyAddress );
415
417
break ;
416
418
417
419
case SOCKS_V5 :
418
- channel . pipeline (). addFirst ( SOCKS_HANDLER , new Socks5ProxyHandler (proxyAddress ) );
420
+ socksProxyHandler = new Socks5ProxyHandler (proxyAddress );
419
421
break ;
420
422
421
423
default :
422
424
throw new IllegalArgumentException ("Only SOCKS4 and SOCKS5 supported at the moment." );
423
425
}
426
+ channel .pipeline ().addFirst (SOCKS_HANDLER , socksProxyHandler );
424
427
}
425
428
});
426
429
promise .setSuccess (socksBootstrap );
0 commit comments