我想使用Netty 4.1编码高性能反向代理服务器。 我的代码是基于Feng-Zihao/protox和Netty Proxy Example的Java改编版本。Netty过滤反向代理
我第一次在处理100-CONTINUE时遇到了一些麻烦,但是在我的管道中添加了HttpObjectAggregator
有点解决了这个问题。
serverBootstrap
.group(bossGroup, workerGroup)
.channel(NioServerSocketChannel.class)
.handler(new LoggingHandler(LogLevel.DEBUG))
.childHandler(new ChannelInitializer<SocketChannel>() {
@Override
public void initChannel(SocketChannel ch) throws Exception {
ch.pipeline().addLast(new LoggingHandler(LogLevel.DEBUG));
ch.pipeline().addLast(new HttpRequestDecoder());
ch.pipeline().addLast(new HttpResponseEncoder());
ch.pipeline().addLast(new HttpObjectAggregator(1048576));
ch.pipeline().addLast(new FrontendHandler());
}
})
// .option(ChannelOption.SO_REUSEADDR, true)
// .option(ChannelOption.SO_BACKLOG, 128)
// .childOption(ChannelOption.SO_KEEPALIVE, true)
.childOption(ChannelOption.AUTO_READ, false)
.bind(port).sync();
在客户端,请求无限期地挂起。 事情是,AUTO_READ在false
似乎阻止HttpObjectAggregator
做他的工作,我的FrontendHandler
只有收到channelActive
事件,但从来没有channelRead
。
它seems though,我需要确保我不会进入读取和远程对等连接之间的竞争条件。我想我最终的目标是选择转发还是不转发基于过滤器(可能是我的FrontendHandler之前的新处理程序)的请求,这需要读取完整的http内容。
我在这里错过了什么吗?