@@ -202,16 +202,17 @@ public boolean remove(Object o) {
202
202
};
203
203
private final ConnectionsPool <String , Channel > connectionsPool ;
204
204
private Semaphore freeConnections = null ;
205
- private final NettyAsyncHttpProviderConfig asyncHttpProviderConfig ;
205
+ private final NettyAsyncHttpProviderConfig providerConfig ;
206
206
private boolean executeConnectAsync = true ;
207
207
public static final ThreadLocal <Boolean > IN_IO_THREAD = new ThreadLocalBoolean ();
208
208
private final boolean trackConnections ;
209
209
private final boolean useRawUrl ;
210
+ private final boolean disableZeroCopy ;
210
211
private final static NTLMEngine ntlmEngine = new NTLMEngine ();
211
212
private static SpnegoEngine spnegoEngine = null ;
212
213
private final Protocol httpProtocol = new HttpProtocol ();
213
214
private final Protocol webSocketProtocol = new WebSocketProtocol ();
214
- private HashedWheelTimer hashedWheelTimer ;
215
+ private final HashedWheelTimer hashedWheelTimer ;
215
216
216
217
private static boolean isNTLM (List <String > auth ) {
217
218
return isNonEmpty (auth ) && auth .get (0 ).startsWith ("NTLM" );
@@ -220,29 +221,29 @@ private static boolean isNTLM(List<String> auth) {
220
221
public NettyAsyncHttpProvider (AsyncHttpClientConfig config ) {
221
222
222
223
if (config .getAsyncHttpProviderConfig () instanceof NettyAsyncHttpProviderConfig ) {
223
- asyncHttpProviderConfig = NettyAsyncHttpProviderConfig .class .cast (config .getAsyncHttpProviderConfig ());
224
+ providerConfig = NettyAsyncHttpProviderConfig .class .cast (config .getAsyncHttpProviderConfig ());
224
225
} else {
225
- asyncHttpProviderConfig = new NettyAsyncHttpProviderConfig ();
226
+ providerConfig = new NettyAsyncHttpProviderConfig ();
226
227
}
227
228
228
229
if (config .getRequestCompressionLevel () > 0 ) {
229
230
LOGGER .warn ("Request was enabled but Netty actually doesn't support this feature" );
230
231
}
231
232
232
- if (asyncHttpProviderConfig .getProperty (USE_BLOCKING_IO ) != null ) {
233
+ if (providerConfig .getProperty (USE_BLOCKING_IO ) != null ) {
233
234
socketChannelFactory = new OioClientSocketChannelFactory (config .executorService ());
234
235
this .allowReleaseSocketChannelFactory = true ;
235
236
} else {
236
237
// check if external NioClientSocketChannelFactory is defined
237
- Object oo = asyncHttpProviderConfig .getProperty (SOCKET_CHANNEL_FACTORY );
238
+ Object oo = providerConfig .getProperty (SOCKET_CHANNEL_FACTORY );
238
239
if (oo instanceof NioClientSocketChannelFactory ) {
239
240
this .socketChannelFactory = NioClientSocketChannelFactory .class .cast (oo );
240
241
241
242
// cannot allow releasing shared channel factory
242
243
this .allowReleaseSocketChannelFactory = false ;
243
244
} else {
244
245
ExecutorService e ;
245
- Object o = asyncHttpProviderConfig .getProperty (BOSS_EXECUTOR_SERVICE );
246
+ Object o = providerConfig .getProperty (BOSS_EXECUTOR_SERVICE );
246
247
if (o instanceof ExecutorService ) {
247
248
e = ExecutorService .class .cast (o );
248
249
} else {
@@ -279,7 +280,7 @@ public NettyAsyncHttpProvider(AsyncHttpClientConfig config) {
279
280
}
280
281
281
282
useRawUrl = config .isUseRawUrl ();
282
-
283
+ disableZeroCopy = providerConfig . isDisableZeroCopy ();
283
284
hashedWheelTimer = new HashedWheelTimer ();
284
285
hashedWheelTimer .start ();
285
286
}
@@ -294,8 +295,8 @@ public String toString() {
294
295
}
295
296
296
297
void configureNetty () {
297
- if (asyncHttpProviderConfig != null ) {
298
- for (Entry <String , Object > entry : asyncHttpProviderConfig .propertiesSet ()) {
298
+ if (providerConfig != null ) {
299
+ for (Entry <String , Object > entry : providerConfig .propertiesSet ()) {
299
300
plainBootstrap .setOption (entry .getKey (), entry .getValue ());
300
301
}
301
302
configureHttpClientCodec ();
@@ -304,7 +305,6 @@ void configureNetty() {
304
305
305
306
plainBootstrap .setPipelineFactory (new ChannelPipelineFactory () {
306
307
307
- /* @Override */
308
308
public ChannelPipeline getPipeline () throws Exception {
309
309
ChannelPipeline pipeline = pipeline ();
310
310
@@ -320,11 +320,11 @@ public ChannelPipeline getPipeline() throws Exception {
320
320
});
321
321
DefaultChannelFuture .setUseDeadLockChecker (false );
322
322
323
- if (asyncHttpProviderConfig != null ) {
324
- Object value = asyncHttpProviderConfig .getProperty (EXECUTE_ASYNC_CONNECT );
323
+ if (providerConfig != null ) {
324
+ Object value = providerConfig .getProperty (EXECUTE_ASYNC_CONNECT );
325
325
if (value instanceof Boolean ) {
326
326
executeConnectAsync = Boolean .class .cast (value );
327
- } else if (asyncHttpProviderConfig .getProperty (DISABLE_NESTED_REQUEST ) != null ) {
327
+ } else if (providerConfig .getProperty (DISABLE_NESTED_REQUEST ) != null ) {
328
328
DefaultChannelFuture .setUseDeadLockChecker (true );
329
329
}
330
330
}
@@ -343,15 +343,15 @@ public ChannelPipeline getPipeline() throws Exception {
343
343
}
344
344
345
345
protected void configureHttpClientCodec () {
346
- httpClientCodecMaxInitialLineLength = asyncHttpProviderConfig .getProperty (HTTP_CLIENT_CODEC_MAX_INITIAL_LINE_LENGTH , Integer .class , httpClientCodecMaxInitialLineLength );
347
- httpClientCodecMaxHeaderSize = asyncHttpProviderConfig .getProperty (HTTP_CLIENT_CODEC_MAX_HEADER_SIZE , Integer .class , httpClientCodecMaxHeaderSize );
348
- httpClientCodecMaxChunkSize = asyncHttpProviderConfig .getProperty (HTTP_CLIENT_CODEC_MAX_CHUNK_SIZE , Integer .class , httpClientCodecMaxChunkSize );
346
+ httpClientCodecMaxInitialLineLength = providerConfig .getProperty (HTTP_CLIENT_CODEC_MAX_INITIAL_LINE_LENGTH , Integer .class , httpClientCodecMaxInitialLineLength );
347
+ httpClientCodecMaxHeaderSize = providerConfig .getProperty (HTTP_CLIENT_CODEC_MAX_HEADER_SIZE , Integer .class , httpClientCodecMaxHeaderSize );
348
+ httpClientCodecMaxChunkSize = providerConfig .getProperty (HTTP_CLIENT_CODEC_MAX_CHUNK_SIZE , Integer .class , httpClientCodecMaxChunkSize );
349
349
}
350
350
351
351
protected void configureHttpsClientCodec () {
352
- httpsClientCodecMaxInitialLineLength = asyncHttpProviderConfig .getProperty (HTTPS_CLIENT_CODEC_MAX_INITIAL_LINE_LENGTH , Integer .class , httpsClientCodecMaxInitialLineLength );
353
- httpsClientCodecMaxHeaderSize = asyncHttpProviderConfig .getProperty (HTTPS_CLIENT_CODEC_MAX_HEADER_SIZE , Integer .class , httpsClientCodecMaxHeaderSize );
354
- httpsClientCodecMaxChunkSize = asyncHttpProviderConfig .getProperty (HTTPS_CLIENT_CODEC_MAX_CHUNK_SIZE , Integer .class , httpsClientCodecMaxChunkSize );
352
+ httpsClientCodecMaxInitialLineLength = providerConfig .getProperty (HTTPS_CLIENT_CODEC_MAX_INITIAL_LINE_LENGTH , Integer .class , httpsClientCodecMaxInitialLineLength );
353
+ httpsClientCodecMaxHeaderSize = providerConfig .getProperty (HTTPS_CLIENT_CODEC_MAX_HEADER_SIZE , Integer .class , httpsClientCodecMaxHeaderSize );
354
+ httpsClientCodecMaxChunkSize = providerConfig .getProperty (HTTPS_CLIENT_CODEC_MAX_CHUNK_SIZE , Integer .class , httpsClientCodecMaxChunkSize );
355
355
}
356
356
357
357
void constructSSLPipeline (final NettyConnectListener <?> cl ) {
@@ -399,8 +399,8 @@ public ChannelPipeline getPipeline() throws Exception {
399
399
}
400
400
});
401
401
402
- if (asyncHttpProviderConfig != null ) {
403
- for (Entry <String , Object > entry : asyncHttpProviderConfig .propertiesSet ()) {
402
+ if (providerConfig != null ) {
403
+ for (Entry <String , Object > entry : providerConfig .propertiesSet ()) {
404
404
secureBootstrap .setOption (entry .getKey (), entry .getValue ());
405
405
secureWebSocketBootstrap .setOption (entry .getKey (), entry .getValue ());
406
406
}
@@ -544,7 +544,7 @@ protected final <T> void writeRequest(final Channel channel, final AsyncHttpClie
544
544
fileLength = raf .length ();
545
545
546
546
ChannelFuture writeFuture ;
547
- if (ssl ) {
547
+ if (ssl || disableZeroCopy ) {
548
548
writeFuture = channel .write (new ChunkedFile (raf , 0 , fileLength , MAX_BUFFERED_BYTES ));
549
549
} else {
550
550
final FileRegion region = new OptimizedFileRegion (raf , 0 , fileLength );
@@ -572,7 +572,7 @@ public void operationComplete(ChannelFuture cf) {
572
572
} else if (body != null ) {
573
573
574
574
ChannelFuture writeFuture ;
575
- if (!ssl && body instanceof RandomAccessBody ) {
575
+ if (!ssl && ! disableZeroCopy && body instanceof RandomAccessBody ) {
576
576
BodyFileRegion bodyFileRegion = new BodyFileRegion ((RandomAccessBody ) body );
577
577
writeFuture = channel .write (bodyFileRegion );
578
578
} else {
@@ -1059,7 +1059,7 @@ private <T> ListenableFuture<T> doConnect(final Request request, final AsyncHand
1059
1059
1060
1060
// Do no enable this with win.
1061
1061
if (!System .getProperty ("os.name" ).toLowerCase (Locale .ENGLISH ).contains ("win" )) {
1062
- bootstrap .setOption ("reuseAddress" , asyncHttpProviderConfig .getProperty (REUSE_ADDRESS ));
1062
+ bootstrap .setOption ("reuseAddress" , providerConfig .getProperty (REUSE_ADDRESS ));
1063
1063
}
1064
1064
1065
1065
try {
0 commit comments