【发布时间】:2021-02-21 15:06:07
【问题描述】:
我有一些当前在 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)));
}
任何提示将不胜感激!
【问题讨论】: