From f52b07dedee99c0d0cf08a3b6732d56290185825 Mon Sep 17 00:00:00 2001 From: Franck Chevassu Date: Wed, 22 Jun 2016 13:58:14 +0200 Subject: [PATCH] Fix HTTP version and Host header in HttpProxyHandler Motivation: The current implementation does not comply with RFC2817 on two points: - The HTTP version required to support the CONNECT method is 1.1, but the current implementation specifies 1.0. - The HOST header should hold the name or address of the Target Host, but the current implementation uses the proxy address instead. Modifications: - Specify HTTP version 1.1, - The HOST header is now set using the Target Host's name (or address, if it is resolved). Result: The CONNECT request is RFC2817-compliant. --- .../java/io/netty/handler/proxy/HttpProxyHandler.java | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/handler-proxy/src/main/java/io/netty/handler/proxy/HttpProxyHandler.java b/handler-proxy/src/main/java/io/netty/handler/proxy/HttpProxyHandler.java index 376b319c02..53d6fbb823 100644 --- a/handler-proxy/src/main/java/io/netty/handler/proxy/HttpProxyHandler.java +++ b/handler-proxy/src/main/java/io/netty/handler/proxy/HttpProxyHandler.java @@ -119,16 +119,13 @@ public final class HttpProxyHandler extends ProxyHandler { rhost = raddr.getAddress().getHostAddress(); } + final String host = rhost + ':' + raddr.getPort(); FullHttpRequest req = new DefaultFullHttpRequest( - HttpVersion.HTTP_1_0, HttpMethod.CONNECT, - rhost + ':' + raddr.getPort(), + HttpVersion.HTTP_1_1, HttpMethod.CONNECT, + host, Unpooled.EMPTY_BUFFER, false); - SocketAddress proxyAddress = proxyAddress(); - if (proxyAddress instanceof InetSocketAddress) { - InetSocketAddress hostAddr = (InetSocketAddress) proxyAddress; - req.headers().set(HttpHeaderNames.HOST, hostAddr.getHostString() + ':' + hostAddr.getPort()); - } + req.headers().set(HttpHeaderNames.HOST, host); if (authorization != null) { req.headers().set(HttpHeaderNames.PROXY_AUTHORIZATION, authorization);