HTTP 到 HTTPS 代理 CONNECT 处理——将代码从 Netty 移植到 Armeria
HTTP to HTTPS proxy CONNECT handling - porting code from Netty to Armeria
我有一些代码目前在 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)));
}
如有任何提示,我们将不胜感激!
不幸的是,Armeria 不允许用户 HttpService
处理 CONNECT
方法。请观看 this issue 以在该功能可用时收到通知。
我有一些代码目前在 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)));
}
如有任何提示,我们将不胜感激!
不幸的是,Armeria 不允许用户 HttpService
处理 CONNECT
方法。请观看 this issue 以在该功能可用时收到通知。