Netty 4.1을 사용하여 고성능 역방향 프록시 서버를 코딩하려고합니다. 자바 적응 코드 Feng-Zihao/protox과 Netty Proxy Example에 기반한 코드입니다.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 필자는 읽기와 원격 피어 연결 사이의 경쟁 상태에 빠지지 않도록해야합니다.
FYI의 마지막 목표는 전체 http 콘텐츠를 읽어야하는 필터 (아마도 FrontendHandler 이전의 새 처리기)를 기반으로 요청을 전달할지 여부를 선택하는 것입니다.
여기에 뭔가가 있습니까?