38
38
import io .netty .resolver .NameResolver ;
39
39
import io .netty .util .Timer ;
40
40
import io .netty .util .concurrent .*;
41
- import io .netty .util .internal .StringUtil ;
41
+ import io .netty .util .internal .PlatformDependent ;
42
42
import org .asynchttpclient .*;
43
43
import org .asynchttpclient .channel .ChannelPool ;
44
44
import org .asynchttpclient .channel .ChannelPoolPartitioning ;
52
52
import org .asynchttpclient .netty .ssl .DefaultSslEngineFactory ;
53
53
import org .asynchttpclient .proxy .ProxyServer ;
54
54
import org .asynchttpclient .uri .Uri ;
55
- import org .asynchttpclient .util .StringUtils ;
56
55
import org .slf4j .Logger ;
57
56
import org .slf4j .LoggerFactory ;
58
57
@@ -126,11 +125,7 @@ public ChannelManager(final AsyncHttpClientConfig config, Timer nettyTimer) {
126
125
TransportFactory <? extends Channel , ? extends EventLoopGroup > transportFactory ;
127
126
if (allowReleaseEventLoopGroup ) {
128
127
if (config .isUseNativeTransport ()) {
129
- if (config .isUseUnixDomain ()){
130
- transportFactory = getDomainTransportFactory ();
131
- }else {
132
- transportFactory = getNativeTransportFactory ();
133
- }
128
+ transportFactory = config .isUseUnixDomain () ? getDomainTransportFactory () : getNativeTransportFactory ();
134
129
} else {
135
130
transportFactory = NioTransportFactory .INSTANCE ;
136
131
}
@@ -145,17 +140,9 @@ public ChannelManager(final AsyncHttpClientConfig config, Timer nettyTimer) {
145
140
}
146
141
transportFactory = NioTransportFactory .INSTANCE ;
147
142
} else if (eventLoopGroup instanceof EpollEventLoopGroup ) {
148
- if (config .isUseUnixDomain ()){
149
- transportFactory = new EpollDomainTransportFactory ();
150
- }else {
151
- transportFactory = new EpollTransportFactory ();
152
- }
143
+ transportFactory = config .isUseUnixDomain () ? new EpollDomainTransportFactory () : new EpollTransportFactory ();
153
144
} else if (eventLoopGroup instanceof KQueueEventLoopGroup ) {
154
- if (config .isUseUnixDomain ()){
155
- transportFactory = new KQueueDomainTransportFactory ();
156
- }else {
157
- transportFactory = new KQueueTransportFactory ();
158
- }
145
+ transportFactory = config .isUseUnixDomain ()? new KQueueDomainTransportFactory ():new KQueueTransportFactory ();
159
146
} else {
160
147
throw new IllegalArgumentException ("Unknown event loop group " + eventLoopGroup .getClass ().getSimpleName ());
161
148
}
@@ -205,27 +192,33 @@ private Bootstrap newBootstrap(ChannelFactory<? extends Channel> channelFactory,
205
192
206
193
@ SuppressWarnings ("unchecked" )
207
194
private TransportFactory <? extends Channel , ? extends EventLoopGroup > getNativeTransportFactory () {
208
- try {
209
- return (TransportFactory <? extends Channel , ? extends EventLoopGroup >) Class .forName ("org.asynchttpclient.netty.channel.EpollTransportFactory" ).newInstance ();
210
- } catch (Exception e ) {
211
- try {
212
- return (TransportFactory <? extends Channel , ? extends EventLoopGroup >) Class .forName ("org.asynchttpclient.netty.channel.KQueueTransportFactory" ).newInstance ();
213
- } catch (Exception e1 ) {
214
- throw new IllegalArgumentException ("No suitable native transport (epoll or kqueue) available" );
215
- }
195
+ String nativeTransportFactoryClassName = null ;
196
+ if (PlatformDependent .isOsx ()) {
197
+ nativeTransportFactoryClassName = "org.asynchttpclient.netty.channel.KQueueTransportFactory" ;
198
+ } else if (!PlatformDependent .isWindows ()) {
199
+ nativeTransportFactoryClassName = "org.asynchttpclient.netty.channel.EpollTransportFactory" ;
216
200
}
201
+ return loadNativeTransportFactory (nativeTransportFactoryClassName );
217
202
}
218
203
219
- private TransportFactory <? extends Channel , ? extends EventLoopGroup > getDomainTransportFactory ( ) {
204
+ private TransportFactory <? extends Channel , ? extends EventLoopGroup > loadNativeTransportFactory ( String nativeTransportFactoryClassName ) {
220
205
try {
221
- return (TransportFactory <? extends Channel , ? extends EventLoopGroup >) Class .forName ("org.asynchttpclient.netty.channel.EpollDomainTransportFactory" ).newInstance ();
222
- } catch (Exception e ) {
223
- try {
224
- return (TransportFactory <? extends Channel , ? extends EventLoopGroup >) Class .forName ("org.asynchttpclient.netty.channel.KQueueDomainTransportFactory" ).newInstance ();
225
- } catch (Exception e1 ) {
226
- throw new IllegalArgumentException ("No suitable native transport (epoll or kqueue) available" );
206
+ if (nativeTransportFactoryClassName != null ) {
207
+ return (TransportFactory <? extends Channel , ? extends EventLoopGroup >) Class .forName (nativeTransportFactoryClassName ).newInstance ();
227
208
}
209
+ } catch (Exception e ) {
210
+ e .printStackTrace ();
211
+ }
212
+ throw new IllegalArgumentException ("No suitable native transport available" );
213
+ }
214
+ private TransportFactory <? extends Channel , ? extends EventLoopGroup > getDomainTransportFactory () {
215
+ String nativeTransportFactoryClassName = null ;
216
+ if (PlatformDependent .isOsx ()) {
217
+ nativeTransportFactoryClassName = "org.asynchttpclient.netty.channel.KQueueDomainTransportFactory" ;
218
+ } else if (!PlatformDependent .isWindows ()) {
219
+ nativeTransportFactoryClassName = "org.asynchttpclient.netty.channel.EpollDomainTransportFactory" ;
228
220
}
221
+ return loadNativeTransportFactory (nativeTransportFactoryClassName );
229
222
}
230
223
231
224
public void configureBootstraps (NettyRequestSender requestSender ) {
@@ -382,6 +375,11 @@ public Future<Channel> updatePipelineForHttpTunneling(ChannelPipeline pipeline,
382
375
383
376
if (requestUri .isWebSocket ()) {
384
377
pipeline .addAfter (AHC_HTTP_HANDLER , AHC_WS_HANDLER , wsHandler );
378
+
379
+ if (config .isEnableWebSocketCompression ()) {
380
+ pipeline .addBefore (AHC_WS_HANDLER , WS_COMPRESSOR_HANDLER , WebSocketClientCompressionHandler .INSTANCE );
381
+ }
382
+
385
383
pipeline .remove (AHC_HTTP_HANDLER );
386
384
}
387
385
return whenHanshaked ;
0 commit comments