我有一些当前在 Netty 中工作的代码,它充当 HTTPS 代理服务器,因此我们处理一个CONNECT方法并将一个 SSL 处理程序动态添加到管道中:
// SimpleChannelInboundHandler<FullHttpRequest>
@Override
protected void channelRead0(ChannelHandlerContext ctx, FullHttpRequest msg) {
if (HttpMethod.CONNECT.equals(msg.method())) { // HTTPS proxy
SslContext sslContext = Utils.getSslContext();
SslHandler sslHandler = sslContext.newHandler(ctx.alloc());
FullHttpResponse response = new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, CONNECTION_ESTABLISHED);
response.headers().set(HttpHeaderNames.CONNECTION, HttpHeaderValues.KEEP_ALIVE);
ctx.writeAndFlush(response).addListener(l -> ctx.channel().pipeline().addFirst(sslHandler));
// do NOT close channel
return;
} else {
// other stuff
}
}
我正在将整个事情移植到 Armeria,并希望得到一些关于如何解决这个问题的提示。我使用以下方法使非 SSL 流程正常工作:
// HttpService
@Override
public HttpResponse serve(ServiceRequestContext ctx, HttpRequest req) throws Exception {
return HttpResponse.from(req.aggregate().thenApply(ahr -> MyServer.handle(ahr)));
}
任何提示将不胜感激!