hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r1423163 - in /httpcomponents/httpclient/branches/4.2.x: RELEASE_NOTES.txt httpclient/src/main/java/org/apache/http/impl/client/DefaultRequestDirector.java httpclient/src/test/java/org/apache/http/impl/client/TestClientAuthentication.java
Date Mon, 17 Dec 2012 21:35:52 GMT
Author: olegk
Date: Mon Dec 17 21:35:51 2012
New Revision: 1423163

URL: http://svn.apache.org/viewvc?rev=1423163&view=rev
Log:
HTTPCLIENT-1279: Target host responding with status 407 (proxy authentication required) causes
an NPE

Modified:
    httpcomponents/httpclient/branches/4.2.x/RELEASE_NOTES.txt
    httpcomponents/httpclient/branches/4.2.x/httpclient/src/main/java/org/apache/http/impl/client/DefaultRequestDirector.java
    httpcomponents/httpclient/branches/4.2.x/httpclient/src/test/java/org/apache/http/impl/client/TestClientAuthentication.java

Modified: httpcomponents/httpclient/branches/4.2.x/RELEASE_NOTES.txt
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/branches/4.2.x/RELEASE_NOTES.txt?rev=1423163&r1=1423162&r2=1423163&view=diff
==============================================================================
--- httpcomponents/httpclient/branches/4.2.x/RELEASE_NOTES.txt (original)
+++ httpcomponents/httpclient/branches/4.2.x/RELEASE_NOTES.txt Mon Dec 17 21:35:51 2012
@@ -1,6 +1,10 @@
 Changes since 4.2.2
 -------------------
 
+* [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>


Modified: httpcomponents/httpclient/branches/4.2.x/httpclient/src/main/java/org/apache/http/impl/client/DefaultRequestDirector.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/branches/4.2.x/httpclient/src/main/java/org/apache/http/impl/client/DefaultRequestDirector.java?rev=1423163&r1=1423162&r2=1423163&view=diff
==============================================================================
--- httpcomponents/httpclient/branches/4.2.x/httpclient/src/main/java/org/apache/http/impl/client/DefaultRequestDirector.java
(original)
+++ httpcomponents/httpclient/branches/4.2.x/httpclient/src/main/java/org/apache/http/impl/client/DefaultRequestDirector.java
Mon Dec 17 21:35:51 2012
@@ -1075,6 +1075,10 @@ public class DefaultRequestDirector impl
             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

Modified: httpcomponents/httpclient/branches/4.2.x/httpclient/src/test/java/org/apache/http/impl/client/TestClientAuthentication.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/branches/4.2.x/httpclient/src/test/java/org/apache/http/impl/client/TestClientAuthentication.java?rev=1423163&r1=1423162&r2=1423163&view=diff
==============================================================================
--- httpcomponents/httpclient/branches/4.2.x/httpclient/src/test/java/org/apache/http/impl/client/TestClientAuthentication.java
(original)
+++ httpcomponents/httpclient/branches/4.2.x/httpclient/src/test/java/org/apache/http/impl/client/TestClientAuthentication.java
Mon Dec 17 21:35:51 2012
@@ -519,4 +519,42 @@ public class TestClientAuthentication ex
         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());
+        this.localServer.start();
+
+        TestCredentialsProvider credsProvider = new TestCredentialsProvider(
+                new UsernamePasswordCredentials("test", "test"));
+
+
+        this.httpclient.setCredentialsProvider(credsProvider);
+
+        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);
+    }
+
 }



Mime
View raw message