From 2eec2251ee11d41506b99ab18b99eeb90f2e535f Mon Sep 17 00:00:00 2001 From: Simone Bordet Date: Wed, 10 Aug 2016 18:36:16 +0200 Subject: [PATCH] Fixes #827 - HTTPClient fails connecting to HTTPS host through an HTTP proxy w/authentication. Only successful (200) responses to a CONNECT behave like HEAD and implicitly have no body. --- .../client/http/HttpReceiverOverHTTP.java | 3 ++- .../proxy/ForwardProxyTLSServerTest.java | 23 +++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/jetty-client/src/main/java/org/eclipse/jetty/client/http/HttpReceiverOverHTTP.java b/jetty-client/src/main/java/org/eclipse/jetty/client/http/HttpReceiverOverHTTP.java index 45d96a734b7..146abbadc82 100644 --- a/jetty-client/src/main/java/org/eclipse/jetty/client/http/HttpReceiverOverHTTP.java +++ b/jetty-client/src/main/java/org/eclipse/jetty/client/http/HttpReceiverOverHTTP.java @@ -205,7 +205,8 @@ public class HttpReceiverOverHTTP extends HttpReceiver implements HttpParser.Res return false; String method = exchange.getRequest().getMethod(); - parser.setHeadResponse(HttpMethod.HEAD.is(method) || HttpMethod.CONNECT.is(method)); + parser.setHeadResponse(HttpMethod.HEAD.is(method) || + (HttpMethod.CONNECT.is(method) && status == HttpStatus.OK_200)); exchange.getResponse().version(version).status(status).reason(reason); return !responseBegin(exchange); diff --git a/jetty-proxy/src/test/java/org/eclipse/jetty/proxy/ForwardProxyTLSServerTest.java b/jetty-proxy/src/test/java/org/eclipse/jetty/proxy/ForwardProxyTLSServerTest.java index 82ed4caa6d8..9d4950e498e 100644 --- a/jetty-proxy/src/test/java/org/eclipse/jetty/proxy/ForwardProxyTLSServerTest.java +++ b/jetty-proxy/src/test/java/org/eclipse/jetty/proxy/ForwardProxyTLSServerTest.java @@ -481,6 +481,29 @@ public class ForwardProxyTLSServerTest }); } + @Test + public void testProxyAuthenticationWithResponseContent() throws Exception + { + final String realm = "test-realm"; + testProxyAuthentication(realm, new ConnectHandler() + { + @Override + public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException + { + String proxyAuth = request.getHeader(HttpHeader.PROXY_AUTHORIZATION.asString()); + if (proxyAuth == null) + { + baseRequest.setHandled(true); + response.setStatus(HttpStatus.PROXY_AUTHENTICATION_REQUIRED_407); + response.setHeader(HttpHeader.PROXY_AUTHENTICATE.asString(), "Basic realm=\"" + realm + "\""); + response.getOutputStream().write(new byte[4096]); + return; + } + super.handle(target, baseRequest, request, response); + } + }); + } + @Test public void testProxyAuthenticationClosesConnection() throws Exception {