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.
This commit is contained in:
Simone Bordet 2016-08-10 18:36:16 +02:00
parent 1bff5c0d6a
commit 2eec2251ee
2 changed files with 25 additions and 1 deletions

View File

@ -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);

View File

@ -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
{