Search in sources :

Example 31 with HttpServerCodec

use of io.netty.handler.codec.http.HttpServerCodec in project weicoder by wdcode.

the class WebSocketServer method handler.

@Override
protected ChannelHandler handler() {
    return new ChannelInitializer<SocketChannel>() {

        @Override
        public void initChannel(final SocketChannel ch) throws Exception {
            ch.pipeline().addLast(new HttpServerCodec());
            ch.pipeline().addLast(new HttpObjectAggregator(1024 * 1024));
            ch.pipeline().addLast(new WebSocketHandler("websocket"));
            ch.config().setAllocator(PooledByteBufAllocator.DEFAULT);
        }
    };
}
Also used : SocketChannel(io.netty.channel.socket.SocketChannel) HttpObjectAggregator(io.netty.handler.codec.http.HttpObjectAggregator) WebSocketHandler(com.weicoder.netty.handler.WebSocketHandler) HttpServerCodec(io.netty.handler.codec.http.HttpServerCodec) ChannelInitializer(io.netty.channel.ChannelInitializer)

Example 32 with HttpServerCodec

use of io.netty.handler.codec.http.HttpServerCodec in project reactor-netty by reactor.

the class ConnectionTest method addByteDecoderWhenNoRight.

@Test
void addByteDecoderWhenNoRight() {
    channel.pipeline().addLast(NettyPipeline.HttpCodec, new HttpServerCodec());
    testContext.addHandlerLast(DECODER_NAME, decoder).addHandlerFirst(DECODER_EXTRACT_NAME, NettyPipeline.inboundHandler(ADD_EXTRACTOR));
    assertThat(channel.pipeline().names()).containsExactly(NettyPipeline.HttpCodec, DECODER_EXTRACT_NAME, DECODER_NAME, TAIL_CONTEXT_NAME);
}
Also used : HttpServerCodec(io.netty.handler.codec.http.HttpServerCodec) Test(org.junit.jupiter.api.Test)

Example 33 with HttpServerCodec

use of io.netty.handler.codec.http.HttpServerCodec in project reactor-netty by reactor.

the class ConnectionTest method addSeveralByteEncodersWhenCodec.

@Test
void addSeveralByteEncodersWhenCodec() {
    ChannelHandler encoder1 = new LineBasedFrameDecoder(12);
    ChannelHandler encoder2 = new LineBasedFrameDecoder(13);
    channel.pipeline().addLast(NettyPipeline.HttpCodec, new HttpServerCodec()).addLast(NettyPipeline.HttpTrafficHandler, httpTrafficHandlerMock).addLast(NettyPipeline.ReactiveBridge, reactiveBridgeMock);
    testContext.addHandlerFirst("encoder1", encoder1).addHandlerFirst("encoder2", encoder2);
    assertThat(channel.pipeline().names()).containsExactly(NettyPipeline.HttpCodec, NettyPipeline.HttpTrafficHandler, "encoder2", "encoder1", NettyPipeline.ReactiveBridge, TAIL_CONTEXT_NAME);
}
Also used : LineBasedFrameDecoder(io.netty.handler.codec.LineBasedFrameDecoder) HttpServerCodec(io.netty.handler.codec.http.HttpServerCodec) ChannelHandler(io.netty.channel.ChannelHandler) Test(org.junit.jupiter.api.Test)

Example 34 with HttpServerCodec

use of io.netty.handler.codec.http.HttpServerCodec in project reactor-netty by reactor.

the class ConnectionTest method addNonByteEncoderWhenFullReactorPipeline.

@Test
void addNonByteEncoderWhenFullReactorPipeline() {
    channel.pipeline().addLast(NettyPipeline.HttpCodec, new HttpServerCodec()).addLast(NettyPipeline.HttpTrafficHandler, httpTrafficHandlerMock).addLast(NettyPipeline.ReactiveBridge, reactiveBridgeMock);
    testContext.addHandlerFirst(ENCODER_NAME, encoder);
    assertThat(channel.pipeline().names()).containsExactly(NettyPipeline.HttpCodec, NettyPipeline.HttpTrafficHandler, ENCODER_NAME, NettyPipeline.ReactiveBridge, TAIL_CONTEXT_NAME);
}
Also used : HttpServerCodec(io.netty.handler.codec.http.HttpServerCodec) Test(org.junit.jupiter.api.Test)

Example 35 with HttpServerCodec

use of io.netty.handler.codec.http.HttpServerCodec in project reactor-netty by reactor.

the class ConnectionTest method addByteEncoderWhenFullReactorPipeline.

@Test
void addByteEncoderWhenFullReactorPipeline() {
    channel.pipeline().addLast(NettyPipeline.HttpCodec, new HttpServerCodec()).addLast(NettyPipeline.HttpTrafficHandler, httpTrafficHandlerMock).addLast(NettyPipeline.ReactiveBridge, reactiveBridgeMock);
    ChannelHandler encoder = new LineBasedFrameDecoder(12);
    testContext.addHandlerFirst(ENCODER_NAME, encoder);
    assertThat(channel.pipeline().names()).containsExactly(NettyPipeline.HttpCodec, NettyPipeline.HttpTrafficHandler, ENCODER_NAME, NettyPipeline.ReactiveBridge, TAIL_CONTEXT_NAME);
}
Also used : HttpServerCodec(io.netty.handler.codec.http.HttpServerCodec) LineBasedFrameDecoder(io.netty.handler.codec.LineBasedFrameDecoder) ChannelHandler(io.netty.channel.ChannelHandler) Test(org.junit.jupiter.api.Test)

Aggregations

HttpServerCodec (io.netty.handler.codec.http.HttpServerCodec)75 ChannelPipeline (io.netty.channel.ChannelPipeline)41 HttpObjectAggregator (io.netty.handler.codec.http.HttpObjectAggregator)35 ChannelHandler (io.netty.channel.ChannelHandler)13 ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)13 ChunkedWriteHandler (io.netty.handler.stream.ChunkedWriteHandler)12 Test (org.junit.jupiter.api.Test)12 HttpServerUpgradeHandler (io.netty.handler.codec.http.HttpServerUpgradeHandler)11 Test (org.junit.Test)11 ServerBootstrap (io.netty.bootstrap.ServerBootstrap)10 LineBasedFrameDecoder (io.netty.handler.codec.LineBasedFrameDecoder)10 Channel (io.netty.channel.Channel)9 NioServerSocketChannel (io.netty.channel.socket.nio.NioServerSocketChannel)9 NioEventLoopGroup (io.netty.channel.nio.NioEventLoopGroup)8 EmbeddedChannel (io.netty.channel.embedded.EmbeddedChannel)7 WebSocketServerProtocolHandler (io.netty.handler.codec.http.websocketx.WebSocketServerProtocolHandler)7 IdleStateHandler (io.netty.handler.timeout.IdleStateHandler)7 ChannelDuplexHandler (io.netty.channel.ChannelDuplexHandler)6 ChannelHandlerAdapter (io.netty.channel.ChannelHandlerAdapter)6 SocketChannel (io.netty.channel.socket.SocketChannel)6