use of org.apache.flink.shaded.netty4.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 TelnetProcessHandler());
p.remove(this);
}
}
use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpServerCodec in project duangframework by tcrct.
the class HttpChannelInitializer method initChannel.
@Override
protected void initChannel(SocketChannel ch) throws Exception {
ChannelPipeline p = ch.pipeline();
if (bootStrap.isSslEnabled()) {
sslContext = bootStrap.getSslContext();
}
// HttpServerCodec包含了默认的HttpRequestDecoder(请求消息解码器)和HttpResponseEncoder(响应解码器)
p.addLast(new HttpServerCodec());
// 为http响应内容添加gizp压缩器
p.addLast(new HttpContentCompressor());
// 目的是将多个消息转换为单一的request或者response对象
p.addLast(new HttpObjectAggregator(1048576));
// 目的是支持异步大文件传输
p.addLast(new ChunkedWriteHandler());
// 真正处理HTTP业务逻辑的地方,针对每个TCP连接创建一个新的ChannelHandler实例
p.addLast(new HttpBaseHandler(bootStrap));
}
use of org.apache.flink.shaded.netty4.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 org.apache.flink.shaded.netty4.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 org.apache.flink.shaded.netty4.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"));
}
Aggregations