Search in sources :

Example 56 with ChunkedWriteHandler

use of io.netty.handler.stream.ChunkedWriteHandler in project async-http-client by AsyncHttpClient.

the class ChannelManager method configureBootstraps.

public void configureBootstraps(NettyRequestSender requestSender) {
    final AsyncHttpClientHandler httpHandler = new HttpHandler(config, this, requestSender);
    wsHandler = new WebSocketHandler(config, this, requestSender);
    final LoggingHandler loggingHandler = new LoggingHandler(LogLevel.TRACE);
    httpBootstrap.handler(new ChannelInitializer<Channel>() {

        @Override
        protected void initChannel(Channel ch) {
            ChannelPipeline pipeline = ch.pipeline().addLast(HTTP_CLIENT_CODEC, newHttpClientCodec()).addLast(INFLATER_HANDLER, newHttpContentDecompressor()).addLast(CHUNKED_WRITER_HANDLER, new ChunkedWriteHandler()).addLast(AHC_HTTP_HANDLER, httpHandler);
            if (LOGGER.isTraceEnabled()) {
                pipeline.addFirst(LOGGING_HANDLER, loggingHandler);
            }
            if (config.getHttpAdditionalChannelInitializer() != null)
                config.getHttpAdditionalChannelInitializer().accept(ch);
        }
    });
    wsBootstrap.handler(new ChannelInitializer<Channel>() {

        @Override
        protected void initChannel(Channel ch) {
            ChannelPipeline pipeline = ch.pipeline().addLast(HTTP_CLIENT_CODEC, newHttpClientCodec()).addLast(AHC_WS_HANDLER, wsHandler);
            if (config.isEnableWebSocketCompression()) {
                pipeline.addBefore(AHC_WS_HANDLER, WS_COMPRESSOR_HANDLER, WebSocketClientCompressionHandler.INSTANCE);
            }
            if (LOGGER.isDebugEnabled()) {
                pipeline.addFirst(LOGGING_HANDLER, loggingHandler);
            }
            if (config.getWsAdditionalChannelInitializer() != null)
                config.getWsAdditionalChannelInitializer().accept(ch);
        }
    });
}
Also used : HttpHandler(org.asynchttpclient.netty.handler.HttpHandler) LoggingHandler(io.netty.handler.logging.LoggingHandler) ChunkedWriteHandler(io.netty.handler.stream.ChunkedWriteHandler) WebSocketHandler(org.asynchttpclient.netty.handler.WebSocketHandler) AsyncHttpClientHandler(org.asynchttpclient.netty.handler.AsyncHttpClientHandler)

Aggregations

ChunkedWriteHandler (io.netty.handler.stream.ChunkedWriteHandler)55 ChannelPipeline (io.netty.channel.ChannelPipeline)28 HttpObjectAggregator (io.netty.handler.codec.http.HttpObjectAggregator)18 HttpServerCodec (io.netty.handler.codec.http.HttpServerCodec)12 SslHandler (io.netty.handler.ssl.SslHandler)12 HttpRequestDecoder (io.netty.handler.codec.http.HttpRequestDecoder)11 IdleStateHandler (io.netty.handler.timeout.IdleStateHandler)11 EmbeddedChannel (io.netty.channel.embedded.EmbeddedChannel)10 HttpResponseEncoder (io.netty.handler.codec.http.HttpResponseEncoder)10 LoggingHandler (io.netty.handler.logging.LoggingHandler)10 ByteBuf (io.netty.buffer.ByteBuf)8 SocketChannel (io.netty.channel.socket.SocketChannel)8 ServerBootstrap (io.netty.bootstrap.ServerBootstrap)6 NioEventLoopGroup (io.netty.channel.nio.NioEventLoopGroup)6 Test (org.junit.Test)6 ChannelFuture (io.netty.channel.ChannelFuture)5 NioServerSocketChannel (io.netty.channel.socket.nio.NioServerSocketChannel)5 ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)4 NioSocketChannel (io.netty.channel.socket.nio.NioSocketChannel)4 HttpClientCodec (io.netty.handler.codec.http.HttpClientCodec)4