@@ -87,7 +87,6 @@ public class ChannelManager {
87
87
private final SslEngineFactory sslEngineFactory ;
88
88
private final EventLoopGroup eventLoopGroup ;
89
89
private final boolean allowReleaseEventLoopGroup ;
90
- private final Class <? extends Channel > socketChannelClass ;
91
90
private final Bootstrap httpBootstrap ;
92
91
private final Bootstrap wsBootstrap ;
93
92
private final long handshakeTimeout ;
@@ -159,6 +158,7 @@ public boolean remove(Object o) {
159
158
// check if external EventLoopGroup is defined
160
159
ThreadFactory threadFactory = config .getThreadFactory () != null ? config .getThreadFactory () : new DefaultThreadFactory (config .getThreadPoolName ());
161
160
allowReleaseEventLoopGroup = config .getEventLoopGroup () == null ;
161
+ Class <? extends Channel > socketChannelClass ;
162
162
if (allowReleaseEventLoopGroup ) {
163
163
if (config .isUseNativeTransport ()) {
164
164
eventLoopGroup = newEpollEventLoopGroup (threadFactory );
@@ -181,23 +181,28 @@ public boolean remove(Object o) {
181
181
}
182
182
}
183
183
184
- httpBootstrap = new Bootstrap (). channel ( socketChannelClass ). group ( eventLoopGroup );
185
- wsBootstrap = new Bootstrap (). channel ( socketChannelClass ). group ( eventLoopGroup );
184
+ httpBootstrap = newBootstrap ( socketChannelClass , eventLoopGroup , config );
185
+ wsBootstrap = newBootstrap ( socketChannelClass , eventLoopGroup , config );
186
186
187
- // default to PooledByteBufAllocator
188
- httpBootstrap .option (ChannelOption .ALLOCATOR , PooledByteBufAllocator .DEFAULT );
189
- wsBootstrap .option (ChannelOption .ALLOCATOR , PooledByteBufAllocator .DEFAULT );
187
+ // for reactive streams
188
+ httpBootstrap .option (ChannelOption .AUTO_READ , false );
189
+ }
190
+
191
+ private Bootstrap newBootstrap (Class <? extends Channel > socketChannelClass , EventLoopGroup eventLoopGroup , AsyncHttpClientConfig config ) {
192
+ Bootstrap bootstrap = new Bootstrap ().channel (socketChannelClass ).group (eventLoopGroup )//
193
+ // default to PooledByteBufAllocator
194
+ .option (ChannelOption .ALLOCATOR , PooledByteBufAllocator .DEFAULT )//
195
+ .option (ChannelOption .AUTO_CLOSE , false );
190
196
191
197
if (config .getConnectTimeout () > 0 ) {
192
- httpBootstrap .option (ChannelOption .CONNECT_TIMEOUT_MILLIS , config .getConnectTimeout ());
193
- wsBootstrap .option (ChannelOption .CONNECT_TIMEOUT_MILLIS , config .getConnectTimeout ());
198
+ bootstrap .option (ChannelOption .CONNECT_TIMEOUT_MILLIS , config .getConnectTimeout ());
194
199
}
200
+
195
201
for (Entry <ChannelOption <Object >, Object > entry : config .getChannelOptions ().entrySet ()) {
196
- ChannelOption <Object > key = entry .getKey ();
197
- Object value = entry .getValue ();
198
- httpBootstrap .option (key , value );
199
- wsBootstrap .option (key , value );
202
+ bootstrap .option (entry .getKey (), entry .getValue ());
200
203
}
204
+
205
+ return bootstrap ;
201
206
}
202
207
203
208
private EventLoopGroup newEpollEventLoopGroup (ThreadFactory threadFactory ) {
@@ -238,8 +243,6 @@ protected void initChannel(Channel ch) throws Exception {
238
243
.addLast (CHUNKED_WRITER_HANDLER , new ChunkedWriteHandler ())//
239
244
.addLast (AHC_HTTP_HANDLER , httpHandler );
240
245
241
- ch .config ().setOption (ChannelOption .AUTO_READ , false );
242
-
243
246
if (config .getHttpAdditionalChannelInitializer () != null )
244
247
config .getHttpAdditionalChannelInitializer ().initChannel (ch );
245
248
}
@@ -376,7 +379,7 @@ private HttpClientCodec newHttpClientCodec() {
376
379
config .getHttpClientCodecMaxInitialLineLength (),//
377
380
config .getHttpClientCodecMaxHeaderSize (),//
378
381
config .getHttpClientCodecMaxChunkSize (),//
379
- false ,
382
+ false ,//
380
383
config .isValidateResponseHeaders ());
381
384
}
382
385
0 commit comments