31
31
import io .netty .handler .codec .http .websocketx .WebSocket08FrameDecoder ;
32
32
import io .netty .handler .codec .http .websocketx .WebSocket08FrameEncoder ;
33
33
import io .netty .handler .codec .http .websocketx .WebSocketFrameAggregator ;
34
+ import io .netty .handler .logging .LoggingHandler ;
34
35
import io .netty .handler .ssl .SslHandler ;
35
36
import io .netty .handler .stream .ChunkedWriteHandler ;
36
37
import io .netty .util .Timer ;
@@ -84,6 +85,7 @@ public class ChannelManager {
84
85
public static final String WS_ENCODER_HANDLER = "ws-encoder" ;
85
86
public static final String AHC_HTTP_HANDLER = "ahc-http" ;
86
87
public static final String AHC_WS_HANDLER = "ahc-ws" ;
88
+ public static final String LOGGING_HANDLER = "logging" ;
87
89
88
90
private final AsyncHttpClientConfig config ;
89
91
private final SslEngineFactory sslEngineFactory ;
@@ -234,16 +236,22 @@ public void configureBootstraps(NettyRequestSender requestSender) {
234
236
235
237
final NoopHandler pinnedEntry = new NoopHandler ();
236
238
239
+ final LoggingHandler loggingHandler = new LoggingHandler ();
240
+
237
241
httpBootstrap .handler (new ChannelInitializer <Channel >() {
238
242
@ Override
239
243
protected void initChannel (Channel ch ) throws Exception {
240
- ch .pipeline ()//
244
+ ChannelPipeline pipeline = ch .pipeline ()//
241
245
.addLast (PINNED_ENTRY , pinnedEntry )//
242
246
.addLast (HTTP_CLIENT_CODEC , newHttpClientCodec ())//
243
247
.addLast (INFLATER_HANDLER , newHttpContentDecompressor ())//
244
248
.addLast (CHUNKED_WRITER_HANDLER , new ChunkedWriteHandler ())//
245
249
.addLast (AHC_HTTP_HANDLER , httpHandler );
246
250
251
+ if (LOGGER .isDebugEnabled ()) {
252
+ pipeline .addAfter (PINNED_ENTRY , LOGGING_HANDLER , loggingHandler );
253
+ }
254
+
247
255
if (config .getHttpAdditionalChannelInitializer () != null )
248
256
config .getHttpAdditionalChannelInitializer ().initChannel (ch );
249
257
}
@@ -252,11 +260,15 @@ protected void initChannel(Channel ch) throws Exception {
252
260
wsBootstrap .handler (new ChannelInitializer <Channel >() {
253
261
@ Override
254
262
protected void initChannel (Channel ch ) throws Exception {
255
- ch .pipeline ()//
263
+ ChannelPipeline pipeline = ch .pipeline ()//
256
264
.addLast (PINNED_ENTRY , pinnedEntry )//
257
265
.addLast (HTTP_CLIENT_CODEC , newHttpClientCodec ())//
258
266
.addLast (AHC_WS_HANDLER , wsHandler );
259
267
268
+ if (LOGGER .isDebugEnabled ()) {
269
+ pipeline .addAfter (PINNED_ENTRY , LOGGING_HANDLER , loggingHandler );
270
+ }
271
+
260
272
if (config .getWsAdditionalChannelInitializer () != null )
261
273
config .getWsAdditionalChannelInitializer ().initChannel (ch );
262
274
}
0 commit comments