HTTPCLIENT-1279: Target host responding with status 407 (proxy authentication required) causes an NPE
git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk@1423172 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
12d11324c0
commit
2aa1fc1400
|
@ -1,8 +1,12 @@
|
|||
Changes in trunk
|
||||
-------------------
|
||||
|
||||
* [HTTPCLIENT-1281] GzipDecompressingEntity does not release InputStream when an IOException occurs
|
||||
while reading the Gzip header.
|
||||
* [HTTPCLIENT-1279] Target host responding with status 407 (proxy authentication required)
|
||||
causes an NPE.
|
||||
Contributed by Oleg Kalnichevski <olegk at apache.org>
|
||||
|
||||
* [HTTPCLIENT-1281] GzipDecompressingEntity does not release InputStream when an IOException
|
||||
occurs while reading the Gzip header.
|
||||
Contributed by Francois-Xavier Bonnet <francois-xavier.bonnet at centraliens.net>
|
||||
|
||||
* [HTTPCLIENT-1277] Caching client sends a 304 to an unconditional request.
|
||||
|
|
|
@ -1075,6 +1075,10 @@ public class DefaultRequestDirector implements RequestDirector {
|
|||
HttpHost proxy = route.getProxyHost();
|
||||
if (this.authenticator.isAuthenticationRequested(proxy, response,
|
||||
this.proxyAuthStrategy, this.proxyAuthState, context)) {
|
||||
// if proxy is not set use target host instead
|
||||
if (proxy == null) {
|
||||
proxy = route.getTargetHost();
|
||||
}
|
||||
if (this.authenticator.authenticate(proxy, response,
|
||||
this.proxyAuthStrategy, this.proxyAuthState, context)) {
|
||||
// Re-try the same request via the same route
|
||||
|
|
|
@ -567,6 +567,10 @@ public class MainClientExec implements ClientExecChain {
|
|||
HttpHost proxy = route.getProxyHost();
|
||||
if (this.authenticator.isAuthenticationRequested(proxy, response,
|
||||
this.proxyAuthStrategy, proxyAuthState, context)) {
|
||||
// if proxy is not set use target host instead
|
||||
if (proxy == null) {
|
||||
proxy = route.getTargetHost();
|
||||
}
|
||||
return this.authenticator.handleAuthChallenge(proxy, response,
|
||||
this.proxyAuthStrategy, proxyAuthState, context);
|
||||
}
|
||||
|
|
|
@ -513,4 +513,38 @@ public class TestClientAuthentication extends IntegrationTestBase {
|
|||
Assert.assertEquals(1, requestHandler.getCount());
|
||||
}
|
||||
|
||||
static class ProxyAuthHandler implements HttpRequestHandler {
|
||||
|
||||
public void handle(
|
||||
final HttpRequest request,
|
||||
final HttpResponse response,
|
||||
final HttpContext context) throws HttpException, IOException {
|
||||
String creds = (String) context.getAttribute("creds");
|
||||
if (creds == null || !creds.equals("test:test")) {
|
||||
response.setStatusCode(HttpStatus.SC_PROXY_AUTHENTICATION_REQUIRED);
|
||||
} else {
|
||||
response.setStatusCode(HttpStatus.SC_OK);
|
||||
StringEntity entity = new StringEntity("success", Consts.ASCII);
|
||||
response.setEntity(entity);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAuthenticationTargetAsProxy() throws Exception {
|
||||
this.localServer.register("*", new ProxyAuthHandler());
|
||||
|
||||
TestCredentialsProvider credsProvider = new TestCredentialsProvider(null);
|
||||
this.httpclient = HttpClients.custom().setCredentialsProvider(credsProvider).build();
|
||||
|
||||
HttpGet httpget = new HttpGet("/");
|
||||
|
||||
HttpResponse response = this.httpclient.execute(getServerHttp(), httpget);
|
||||
HttpEntity entity = response.getEntity();
|
||||
Assert.assertEquals(HttpStatus.SC_PROXY_AUTHENTICATION_REQUIRED,
|
||||
response.getStatusLine().getStatusCode());
|
||||
EntityUtils.consume(entity);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue