nettyarmeria

HTTP to HTTPS proxy CONNECT handling - porting code from Netty to Armeria


I have some code that currently works in Netty, which acts as an HTTPS proxy server, so we handle a CONNECT method and add an SSL handler to the pipeline on the fly:

// 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
    }

}

I am porting this whole thing to Armeria and would like some hints on how to approach this. I have the non-SSL flows working fine using something like this:

// HttpService

@Override
public HttpResponse serve(ServiceRequestContext ctx, HttpRequest req) throws Exception {
    return HttpResponse.from(req.aggregate().thenApply(ahr -> MyServer.handle(ahr)));
}

Any tips would be appreciated !


Solution

  • Armeria unfortunately doesn't allow a user HttpService to handle CONNECT method. Please watch this issue to get notified when the feature is available.