Skip to content

Commit

Permalink
add keep-alive headers to connect response
Browse files Browse the repository at this point in the history
I think the problem is there's no SSL handshake – the original CONNECT request is getting slung over to the SSL proxy. LittleProxy is doing effectively this but with an earlier version of Netty so it's quite hard to figure out what's going on.
  • Loading branch information
robfletcher committed Aug 9, 2013
1 parent 3c5f9c2 commit 21b0f62
Showing 1 changed file with 11 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import io.netty.channel.*;
import io.netty.channel.socket.nio.*;
import io.netty.handler.codec.http.*;
import static io.netty.handler.codec.http.HttpHeaders.Names.CONNECTION;
import static io.netty.handler.codec.http.HttpHeaders.Values.KEEP_ALIVE;
import static io.netty.handler.codec.http.HttpMethod.*;

public class ProxyConnectHandler extends SimpleChannelInboundHandler<HttpRequest> {
Expand All @@ -27,8 +29,8 @@ protected void channelRead0(final ChannelHandlerContext context, final HttpReque
CallbackNotifier callback = new CallbackNotifier() {
@Override
public void onSuccess(final ChannelHandlerContext outboundContext) {
HttpResponse response = new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK);
context.channel().writeAndFlush(response)
context.channel()
.writeAndFlush(createConnectResponse())
.addListener(new ChannelFutureListener() {
@Override
public void operationComplete(ChannelFuture channelFuture) {
Expand Down Expand Up @@ -56,6 +58,13 @@ public void onFailure(ChannelHandlerContext outboundCtx, Throwable cause) {
bootstrap.connect(proxyAddress);
}

private HttpResponse createConnectResponse() {
DefaultHttpResponse response = new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK);
response.headers().add(CONNECTION, KEEP_ALIVE);
response.headers().add("Proxy-Connection", KEEP_ALIVE);
return response;
}

private boolean isConnectRequest(HttpRequest request) {
return CONNECT.equals(request.getMethod());
}
Expand Down

0 comments on commit 21b0f62

Please sign in to comment.