use of io.netty.handler.codec.http.HttpServerCodec in project reactor-netty by reactor.
the class NettyContextTest method addSeveralByteEncodersWhenCodec.
@Test
public void addSeveralByteEncodersWhenCodec() throws Exception {
ChannelHandler encoder1 = new LineBasedFrameDecoder(12);
ChannelHandler encoder2 = new LineBasedFrameDecoder(13);
channel.pipeline().addLast(NettyPipeline.HttpCodec, new HttpServerCodec()).addLast(NettyPipeline.HttpServerHandler, new ChannelDuplexHandler()).addLast(NettyPipeline.ReactiveBridge, new ChannelHandlerAdapter() {
});
testContext.addHandlerFirst("encoder1", encoder1).addHandlerFirst("encoder2", encoder2);
assertEquals(channel.pipeline().names(), Arrays.asList(NettyPipeline.HttpCodec, NettyPipeline.HttpServerHandler, "encoder2", "encoder1", NettyPipeline.ReactiveBridge, "DefaultChannelPipeline$TailContext#0"));
}
use of io.netty.handler.codec.http.HttpServerCodec in project reactor-netty by reactor.
the class NettyContextTest method addNonByteDecoderWhenFullReactorPipeline.
@Test
public void addNonByteDecoderWhenFullReactorPipeline() throws Exception {
channel.pipeline().addLast(NettyPipeline.HttpCodec, new HttpServerCodec()).addLast(NettyPipeline.HttpServerHandler, new ChannelDuplexHandler()).addLast(NettyPipeline.ReactiveBridge, new ChannelHandlerAdapter() {
});
ChannelHandler decoder = new ChannelHandlerAdapter() {
};
testContext.addHandlerLast("decoder", decoder);
assertEquals(channel.pipeline().names(), Arrays.asList(NettyPipeline.HttpCodec, NettyPipeline.HttpServerHandler, "decoder", NettyPipeline.ReactiveBridge, "DefaultChannelPipeline$TailContext#0"));
}
use of io.netty.handler.codec.http.HttpServerCodec in project reactor-netty by reactor.
the class NettyContextTest method addSeveralByteDecodersWhenCodec.
@Test
public void addSeveralByteDecodersWhenCodec() throws Exception {
ChannelHandler decoder1 = new LineBasedFrameDecoder(12);
ChannelHandler decoder2 = new LineBasedFrameDecoder(13);
channel.pipeline().addLast(NettyPipeline.HttpCodec, new HttpServerCodec()).addLast(NettyPipeline.HttpServerHandler, new ChannelDuplexHandler()).addLast(NettyPipeline.ReactiveBridge, new ChannelHandlerAdapter() {
});
testContext.addHandlerLast("decoder1$extract", NettyPipeline.inboundHandler(ADD_EXTRACTOR)).addHandlerLast("decoder1", decoder1).addHandlerLast("decoder2$extract", NettyPipeline.inboundHandler(ADD_EXTRACTOR)).addHandlerLast("decoder2", decoder2);
assertEquals(channel.pipeline().names(), Arrays.asList(NettyPipeline.HttpCodec, NettyPipeline.HttpServerHandler, "decoder1$extract", "decoder1", "decoder2$extract", "decoder2", NettyPipeline.ReactiveBridge, "DefaultChannelPipeline$TailContext#0"));
}
use of io.netty.handler.codec.http.HttpServerCodec in project summer by foxsugar.
the class WebSocketServerInitializer method initChannel.
@Override
protected void initChannel(SocketChannel ch) throws Exception {
ChannelPipeline pipeline = ch.pipeline();
// 处理日志
// pipeline.addLast(new LoggingHandler(LogLevel.INFO));
// 处理心跳
// pipeline.addLast(new IdleStateHandler(15, 0, 0, TimeUnit.SECONDS));
// pipeline.addLast(new ChatHeartbeatHandler());
// // 获取职责链
// pipeline.addLast("http-codec", new HttpServerCodec());
// pipeline.addLast("aggregator", new HttpObjectAggregator(64*1024));
// pipeline.addLast("http-chunked", new ChunkedWriteHandler());
// // pipeline.addLast(new WebSocketServerCompressionHandler());
//
// // pipeline.addLast("encoder", new WsEncoder());
// // pipeline.addLast("decoder", new WsDecoder());
// pipeline.addLast("handshake",new WebSocketServerProtocolHandler("/ws"));
// pipeline.addLast(new WsCodec());
// // pipeline.addLast(new WsGameMsgHandler());
// pipeline.addLast(new WsHandler());
// // pipeline.addLast("codec", new WsEncoder());
// //websocket定义了传递数据的6中frame类型
// // pipeline.addLast(new GameMsgHandler());
//
pipeline.addLast(new HttpServerCodec());
pipeline.addLast(new HttpObjectAggregator(64 * 1024));
pipeline.addLast(new WebSocketServerProtocolHandler("/websocket", null, true));
pipeline.addLast(new WsCodec());
pipeline.addLast(new GameMsgHandler());
// ChannelPipeline pipeline = ch.pipeline();
// pipeline.addLast(new HttpServerCodec());
// pipeline.addLast(new HttpObjectAggregator(65536));
// // pipeline.addLast(new WebSocketServerCompressionHandler());
// // pipeline.addLast(new WebSocketServerProtocolHandler(WEBSOCKET_PATH, null, true));
// // pipeline.addLast(new WebSocketIndexPageHandler(WEBSOCKET_PATH));
// pipeline.addLast(new WebSocketServerHandler());
}
use of io.netty.handler.codec.http.HttpServerCodec in project dubbo by alibaba.
the class QosProcessHandler method decode.
@Override
protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception {
if (in.readableBytes() < 1) {
return;
}
// read one byte to guess protocol
final int magic = in.getByte(in.readerIndex());
ChannelPipeline p = ctx.pipeline();
p.addLast(new LocalHostPermitHandler(acceptForeignIp));
if (isHttp(magic)) {
// no welcome output for http protocol
if (welcomeFuture != null && welcomeFuture.isCancellable()) {
welcomeFuture.cancel(false);
}
p.addLast(new HttpServerCodec());
p.addLast(new HttpObjectAggregator(1048576));
p.addLast(new HttpProcessHandler());
p.remove(this);
} else {
p.addLast(new LineBasedFrameDecoder(2048));
p.addLast(new StringDecoder(CharsetUtil.UTF_8));
p.addLast(new StringEncoder(CharsetUtil.UTF_8));
p.addLast(new IdleStateHandler(0, 0, 5 * 60));
p.addLast(new TelnetIdleEventHandler());
p.addLast(new TelnetProcessHandler());
p.remove(this);
}
}
Aggregations