hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r1349864 - in /httpcomponents/httpclient/branches/decorator-refactoring/httpclient/src/main/java/org/apache/http: client/protocol/ impl/client/ impl/client/exec/
Date Wed, 13 Jun 2012 14:09:16 GMT
Author: olegk
Date: Wed Jun 13 14:09:15 2012
New Revision: 1349864

URL: http://svn.apache.org/viewvc?rev=1349864&view=rev
Log:
Moved authentication response code from protocol interceptors to the HttpAuthenticator class;
deprecated old authentication protocol interceptors

Modified:
    httpcomponents/httpclient/branches/decorator-refactoring/httpclient/src/main/java/org/apache/http/client/protocol/RequestAuthenticationBase.java
    httpcomponents/httpclient/branches/decorator-refactoring/httpclient/src/main/java/org/apache/http/client/protocol/RequestProxyAuthentication.java
    httpcomponents/httpclient/branches/decorator-refactoring/httpclient/src/main/java/org/apache/http/client/protocol/RequestTargetAuthentication.java
    httpcomponents/httpclient/branches/decorator-refactoring/httpclient/src/main/java/org/apache/http/impl/client/HttpAuthenticator.java
    httpcomponents/httpclient/branches/decorator-refactoring/httpclient/src/main/java/org/apache/http/impl/client/ProxyClient.java
    httpcomponents/httpclient/branches/decorator-refactoring/httpclient/src/main/java/org/apache/http/impl/client/exec/MainRequestExecutor.java

Modified: httpcomponents/httpclient/branches/decorator-refactoring/httpclient/src/main/java/org/apache/http/client/protocol/RequestAuthenticationBase.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/branches/decorator-refactoring/httpclient/src/main/java/org/apache/http/client/protocol/RequestAuthenticationBase.java?rev=1349864&r1=1349863&r2=1349864&view=diff
==============================================================================
--- httpcomponents/httpclient/branches/decorator-refactoring/httpclient/src/main/java/org/apache/http/client/protocol/RequestAuthenticationBase.java
(original)
+++ httpcomponents/httpclient/branches/decorator-refactoring/httpclient/src/main/java/org/apache/http/client/protocol/RequestAuthenticationBase.java
Wed Jun 13 14:09:15 2012
@@ -44,6 +44,7 @@ import org.apache.http.auth.ContextAware
 import org.apache.http.auth.Credentials;
 import org.apache.http.protocol.HttpContext;
 
+@Deprecated
 abstract class RequestAuthenticationBase implements HttpRequestInterceptor {
 
     final Log log = LogFactory.getLog(getClass());
@@ -112,7 +113,6 @@ abstract class RequestAuthenticationBase
         }
     }
 
-    @SuppressWarnings("deprecation")
     private Header authenticate(
             final AuthScheme authScheme,
             final Credentials creds,

Modified: httpcomponents/httpclient/branches/decorator-refactoring/httpclient/src/main/java/org/apache/http/client/protocol/RequestProxyAuthentication.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/branches/decorator-refactoring/httpclient/src/main/java/org/apache/http/client/protocol/RequestProxyAuthentication.java?rev=1349864&r1=1349863&r2=1349864&view=diff
==============================================================================
--- httpcomponents/httpclient/branches/decorator-refactoring/httpclient/src/main/java/org/apache/http/client/protocol/RequestProxyAuthentication.java
(original)
+++ httpcomponents/httpclient/branches/decorator-refactoring/httpclient/src/main/java/org/apache/http/client/protocol/RequestProxyAuthentication.java
Wed Jun 13 14:09:15 2012
@@ -36,6 +36,7 @@ import org.apache.http.auth.AUTH;
 import org.apache.http.auth.AuthState;
 import org.apache.http.conn.HttpRoutedConnection;
 import org.apache.http.conn.routing.HttpRoute;
+import org.apache.http.impl.client.HttpAuthenticator;
 import org.apache.http.protocol.ExecutionContext;
 import org.apache.http.protocol.HttpContext;
 
@@ -44,7 +45,10 @@ import org.apache.http.protocol.HttpCont
  * based on the actual state of the HTTP authentication context.
  *
  * @since 4.0
+ *
+ * @deprecated (4.3) use {@link HttpAuthenticator}.
  */
+@Deprecated
 @Immutable
 public class RequestProxyAuthentication extends RequestAuthenticationBase {
 

Modified: httpcomponents/httpclient/branches/decorator-refactoring/httpclient/src/main/java/org/apache/http/client/protocol/RequestTargetAuthentication.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/branches/decorator-refactoring/httpclient/src/main/java/org/apache/http/client/protocol/RequestTargetAuthentication.java?rev=1349864&r1=1349863&r2=1349864&view=diff
==============================================================================
--- httpcomponents/httpclient/branches/decorator-refactoring/httpclient/src/main/java/org/apache/http/client/protocol/RequestTargetAuthentication.java
(original)
+++ httpcomponents/httpclient/branches/decorator-refactoring/httpclient/src/main/java/org/apache/http/client/protocol/RequestTargetAuthentication.java
Wed Jun 13 14:09:15 2012
@@ -34,6 +34,7 @@ import org.apache.http.HttpRequest;
 import org.apache.http.annotation.Immutable;
 import org.apache.http.auth.AUTH;
 import org.apache.http.auth.AuthState;
+import org.apache.http.impl.client.HttpAuthenticator;
 import org.apache.http.protocol.HttpContext;
 
 /**
@@ -41,7 +42,10 @@ import org.apache.http.protocol.HttpCont
  * based on the actual state of the HTTP authentication context.
  *
  * @since 4.0
+ *
+ * @deprecated (4.3) use {@link HttpAuthenticator}.
  */
+@Deprecated
 @Immutable
 public class RequestTargetAuthentication extends RequestAuthenticationBase {
 

Modified: httpcomponents/httpclient/branches/decorator-refactoring/httpclient/src/main/java/org/apache/http/impl/client/HttpAuthenticator.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/branches/decorator-refactoring/httpclient/src/main/java/org/apache/http/impl/client/HttpAuthenticator.java?rev=1349864&r1=1349863&r2=1349864&view=diff
==============================================================================
--- httpcomponents/httpclient/branches/decorator-refactoring/httpclient/src/main/java/org/apache/http/impl/client/HttpAuthenticator.java
(original)
+++ httpcomponents/httpclient/branches/decorator-refactoring/httpclient/src/main/java/org/apache/http/impl/client/HttpAuthenticator.java
Wed Jun 13 14:09:15 2012
@@ -27,6 +27,7 @@
 
 package org.apache.http.impl.client;
 
+import java.io.IOException;
 import java.util.Locale;
 import java.util.Map;
 import java.util.Queue;
@@ -34,12 +35,17 @@ import java.util.Queue;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.http.Header;
+import org.apache.http.HttpException;
 import org.apache.http.HttpHost;
+import org.apache.http.HttpRequest;
 import org.apache.http.HttpResponse;
 import org.apache.http.auth.AuthProtocolState;
 import org.apache.http.auth.AuthOption;
 import org.apache.http.auth.AuthScheme;
 import org.apache.http.auth.AuthState;
+import org.apache.http.auth.AuthenticationException;
+import org.apache.http.auth.ContextAwareAuthScheme;
+import org.apache.http.auth.Credentials;
 import org.apache.http.auth.MalformedChallengeException;
 import org.apache.http.client.AuthenticationStrategy;
 import org.apache.http.protocol.HttpContext;
@@ -81,7 +87,24 @@ public class HttpAuthenticator {
         }
     }
 
-    public boolean authenticate(
+    /**
+     * @deprecated (4.3) use {@link #handleAuthChallenge(
+     *   HttpHost, HttpResponse, AuthenticationStrategy, AuthState, HttpContext)}.
+     */
+    @Deprecated
+    public boolean authenticate (
+            final HttpHost host,
+            final HttpResponse response,
+            final AuthenticationStrategy authStrategy,
+            final AuthState authState,
+            final HttpContext context) {
+        return handleAuthChallenge(host, response, authStrategy, authState, context);
+    }
+
+    /**
+     * @since 4.3
+     */
+    public boolean handleAuthChallenge(
             final HttpHost host,
             final HttpResponse response,
             final AuthenticationStrategy authStrategy,
@@ -156,4 +179,80 @@ public class HttpAuthenticator {
         }
     }
 
+    /**
+     * @since 4.3
+     */
+    public void generateAuthResponse(
+            final HttpRequest request,
+            final AuthState authState,
+            final HttpContext context) throws HttpException, IOException {
+        AuthScheme authScheme = authState.getAuthScheme();
+        Credentials creds = authState.getCredentials();
+        switch (authState.getState()) {
+        case FAILURE:
+            return;
+        case SUCCESS:
+            ensureAuthScheme(authScheme);
+            if (authScheme.isConnectionBased()) {
+                return;
+            }
+            break;
+        case CHALLENGED:
+            Queue<AuthOption> authOptions = authState.getAuthOptions();
+            if (authOptions != null) {
+                while (!authOptions.isEmpty()) {
+                    AuthOption authOption = authOptions.remove();
+                    authScheme = authOption.getAuthScheme();
+                    creds = authOption.getCredentials();
+                    authState.update(authScheme, creds);
+                    if (this.log.isDebugEnabled()) {
+                        this.log.debug("Generating response to an authentication challenge
using "
+                                + authScheme.getSchemeName() + " scheme");
+                    }
+                    try {
+                        Header header = doAuth(authScheme, creds, request, context);
+                        request.addHeader(header);
+                        break;
+                    } catch (AuthenticationException ex) {
+                        if (this.log.isWarnEnabled()) {
+                            this.log.warn(authScheme + " authentication error: " + ex.getMessage());
+                        }
+                    }
+                }
+                return;
+            } else {
+                ensureAuthScheme(authScheme);
+            }
+        }
+        if (authScheme != null) {
+            try {
+                Header header = doAuth(authScheme, creds, request, context);
+                request.addHeader(header);
+            } catch (AuthenticationException ex) {
+                if (this.log.isErrorEnabled()) {
+                    this.log.error(authScheme + " authentication error: " + ex.getMessage());
+                }
+            }
+        }
+    }
+
+    private void ensureAuthScheme(final AuthScheme authScheme) {
+        if (authScheme == null) {
+            throw new IllegalStateException("Auth scheme is not set");
+        }
+    }
+
+    @SuppressWarnings("deprecation")
+    private Header doAuth(
+            final AuthScheme authScheme,
+            final Credentials creds,
+            final HttpRequest request,
+            final HttpContext context) throws AuthenticationException {
+        if (authScheme instanceof ContextAwareAuthScheme) {
+            return ((ContextAwareAuthScheme) authScheme).authenticate(creds, request, context);
+        } else {
+            return authScheme.authenticate(creds, request);
+        }
+    }
+
 }

Modified: httpcomponents/httpclient/branches/decorator-refactoring/httpclient/src/main/java/org/apache/http/impl/client/ProxyClient.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/branches/decorator-refactoring/httpclient/src/main/java/org/apache/http/impl/client/ProxyClient.java?rev=1349864&r1=1349863&r2=1349864&view=diff
==============================================================================
--- httpcomponents/httpclient/branches/decorator-refactoring/httpclient/src/main/java/org/apache/http/impl/client/ProxyClient.java
(original)
+++ httpcomponents/httpclient/branches/decorator-refactoring/httpclient/src/main/java/org/apache/http/impl/client/ProxyClient.java
Wed Jun 13 14:09:15 2012
@@ -40,6 +40,7 @@ import org.apache.http.HttpRequest;
 import org.apache.http.HttpRequestInterceptor;
 import org.apache.http.HttpResponse;
 import org.apache.http.ProtocolVersion;
+import org.apache.http.auth.AUTH;
 import org.apache.http.auth.AuthSchemeRegistry;
 import org.apache.http.auth.AuthScope;
 import org.apache.http.auth.AuthState;
@@ -48,7 +49,6 @@ import org.apache.http.client.params.Aut
 import org.apache.http.client.params.HttpClientParams;
 import org.apache.http.client.protocol.ClientContext;
 import org.apache.http.client.protocol.RequestClientConnControl;
-import org.apache.http.client.protocol.RequestProxyAuthentication;
 import org.apache.http.conn.HttpRoutedConnection;
 import org.apache.http.conn.routing.HttpRoute;
 import org.apache.http.entity.BufferedHttpEntity;
@@ -69,8 +69,6 @@ import org.apache.http.protocol.HttpCont
 import org.apache.http.protocol.HttpProcessor;
 import org.apache.http.protocol.HttpRequestExecutor;
 import org.apache.http.protocol.ImmutableHttpProcessor;
-import org.apache.http.protocol.RequestContent;
-import org.apache.http.protocol.RequestTargetHost;
 import org.apache.http.protocol.RequestUserAgent;
 import org.apache.http.util.EntityUtils;
 
@@ -91,11 +89,8 @@ public class ProxyClient {
             throw new IllegalArgumentException("HTTP parameters may not be null");
         }
         this.httpProcessor = new ImmutableHttpProcessor(new HttpRequestInterceptor[] {
-                new RequestContent(),
-                new RequestTargetHost(),
                 new RequestClientConnControl(),
-                new RequestUserAgent(),
-                new RequestProxyAuthentication()
+                new RequestUserAgent()
         } );
         this.requestExec = new HttpRequestExecutor();
         this.proxyAuthStrategy = new ProxyAuthenticationStrategy();
@@ -131,45 +126,46 @@ public class ProxyClient {
         HttpContext context = new BasicHttpContext();
         HttpResponse response = null;
 
+        String host = target.getHostName();
+        int port = target.getPort();
+        if (port < 0) {
+            port = 80;
+        }
+
+        StringBuilder buffer = new StringBuilder(host.length() + 6);
+        buffer.append(host);
+        buffer.append(':');
+        buffer.append(Integer.toString(port));
+
+        String authority = buffer.toString();
+        ProtocolVersion ver = HttpProtocolParams.getVersion(this.params);
+        HttpRequest connect = new BasicHttpRequest("CONNECT", authority, ver);
+        connect.setParams(this.params);
+
+        BasicCredentialsProvider credsProvider = new BasicCredentialsProvider();
+        credsProvider.setCredentials(new AuthScope(proxy), credentials);
+
+        // Populate the execution context
+        context.setAttribute(ExecutionContext.HTTP_TARGET_HOST, target);
+        context.setAttribute(ExecutionContext.HTTP_PROXY_HOST, proxy);
+        context.setAttribute(ExecutionContext.HTTP_CONNECTION, conn);
+        context.setAttribute(ExecutionContext.HTTP_REQUEST, connect);
+        context.setAttribute(ClientContext.PROXY_AUTH_STATE, this.proxyAuthState);
+        context.setAttribute(ClientContext.CREDS_PROVIDER, credsProvider);
+        context.setAttribute(ClientContext.AUTHSCHEME_REGISTRY, this.authSchemeRegistry);
+
+        this.requestExec.preProcess(connect, this.httpProcessor, context);
+
         for (;;) {
             if (!conn.isOpen()) {
                 Socket socket = new Socket(proxy.getHostName(), proxy.getPort());
                 conn.bind(socket, this.params);
             }
-            String host = target.getHostName();
-            int port = target.getPort();
-            if (port < 0) {
-                port = 80;
-            }
 
-            StringBuilder buffer = new StringBuilder(host.length() + 6);
-            buffer.append(host);
-            buffer.append(':');
-            buffer.append(Integer.toString(port));
-
-            String authority = buffer.toString();
-            ProtocolVersion ver = HttpProtocolParams.getVersion(this.params);
-            HttpRequest connect = new BasicHttpRequest("CONNECT", authority, ver);
-            connect.setParams(this.params);
-
-            BasicCredentialsProvider credsProvider = new BasicCredentialsProvider();
-            credsProvider.setCredentials(new AuthScope(proxy), credentials);
-
-            // Populate the execution context
-            context.setAttribute(ExecutionContext.HTTP_TARGET_HOST, target);
-            context.setAttribute(ExecutionContext.HTTP_PROXY_HOST, proxy);
-            context.setAttribute(ExecutionContext.HTTP_CONNECTION, conn);
-            context.setAttribute(ExecutionContext.HTTP_REQUEST, connect);
-            context.setAttribute(ClientContext.PROXY_AUTH_STATE, this.proxyAuthState);
-            context.setAttribute(ClientContext.CREDS_PROVIDER, credsProvider);
-            context.setAttribute(ClientContext.AUTHSCHEME_REGISTRY, this.authSchemeRegistry);
-
-            this.requestExec.preProcess(connect, this.httpProcessor, context);
+            this.authenticator.generateAuthResponse(connect, this.proxyAuthState, context);
 
             response = this.requestExec.execute(connect, conn, context);
-
             response.setParams(this.params);
-            this.requestExec.postProcess(response, this.httpProcessor, context);
 
             int status = response.getStatusLine().getStatusCode();
             if (status < 200) {
@@ -180,7 +176,7 @@ public class ProxyClient {
             if (HttpClientParams.isAuthenticating(this.params)) {
                 if (this.authenticator.isAuthenticationRequested(proxy, response,
                         this.proxyAuthStrategy, this.proxyAuthState, context)) {
-                    if (this.authenticator.authenticate(proxy, response,
+                    if (this.authenticator.handleAuthChallenge(proxy, response,
                             this.proxyAuthStrategy, this.proxyAuthState, context)) {
                         // Retry request
                         if (this.reuseStrategy.keepAlive(response, context)) {
@@ -190,6 +186,8 @@ public class ProxyClient {
                         } else {
                             conn.close();
                         }
+                        // discard previous auth header
+                        connect.removeHeaders(AUTH.PROXY_AUTH_RESP);
                     } else {
                         break;
                     }

Modified: httpcomponents/httpclient/branches/decorator-refactoring/httpclient/src/main/java/org/apache/http/impl/client/exec/MainRequestExecutor.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/branches/decorator-refactoring/httpclient/src/main/java/org/apache/http/impl/client/exec/MainRequestExecutor.java?rev=1349864&r1=1349863&r2=1349864&view=diff
==============================================================================
--- httpcomponents/httpclient/branches/decorator-refactoring/httpclient/src/main/java/org/apache/http/impl/client/exec/MainRequestExecutor.java
(original)
+++ httpcomponents/httpclient/branches/decorator-refactoring/httpclient/src/main/java/org/apache/http/impl/client/exec/MainRequestExecutor.java
Wed Jun 13 14:09:15 2012
@@ -34,14 +34,15 @@ import java.util.concurrent.TimeUnit;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.http.ConnectionReuseStrategy;
-import org.apache.http.Header;
 import org.apache.http.HttpEntity;
 import org.apache.http.HttpException;
 import org.apache.http.HttpHost;
 import org.apache.http.HttpRequest;
+import org.apache.http.HttpRequestInterceptor;
 import org.apache.http.HttpResponse;
 import org.apache.http.ProtocolVersion;
 import org.apache.http.annotation.ThreadSafe;
+import org.apache.http.auth.AUTH;
 import org.apache.http.auth.AuthProtocolState;
 import org.apache.http.auth.AuthState;
 import org.apache.http.auth.UsernamePasswordCredentials;
@@ -51,6 +52,7 @@ import org.apache.http.client.UserTokenH
 import org.apache.http.client.methods.HttpExecutionAware;
 import org.apache.http.client.params.HttpClientParams;
 import org.apache.http.client.protocol.ClientContext;
+import org.apache.http.client.protocol.RequestClientConnControl;
 import org.apache.http.conn.ClientConnectionManager;
 import org.apache.http.conn.ClientConnectionRequest;
 import org.apache.http.conn.ConnectionKeepAliveStrategy;
@@ -73,6 +75,8 @@ import org.apache.http.protocol.Executio
 import org.apache.http.protocol.HttpContext;
 import org.apache.http.protocol.HttpProcessor;
 import org.apache.http.protocol.HttpRequestExecutor;
+import org.apache.http.protocol.ImmutableHttpProcessor;
+import org.apache.http.protocol.RequestUserAgent;
 import org.apache.http.util.EntityUtils;
 
 /**
@@ -111,7 +115,7 @@ public class MainRequestExecutor impleme
     private final ConnectionReuseStrategy reuseStrategy;
     private final ConnectionKeepAliveStrategy keepAliveStrategy;
     private final HttpRequestExecutor requestExec;
-    private final HttpProcessor httpProcessor;
+    private final HttpProcessor proxyHttpProcessor;
     private final AuthenticationStrategy targetAuthStrategy;
     private final AuthenticationStrategy proxyAuthStrategy;
     private final HttpAuthenticator authenticator;
@@ -119,7 +123,6 @@ public class MainRequestExecutor impleme
     private final HttpParams params;
 
     public MainRequestExecutor(
-            final HttpProcessor httpProcessor,
             final ClientConnectionManager connManager,
             final ConnectionReuseStrategy reuseStrategy,
             final ConnectionKeepAliveStrategy keepAliveStrategy,
@@ -127,9 +130,6 @@ public class MainRequestExecutor impleme
             final AuthenticationStrategy proxyAuthStrategy,
             final UserTokenHandler userTokenHandler,
             final HttpParams params) {
-        if (httpProcessor == null) {
-            throw new IllegalArgumentException("HTTP protocol processor may not be null");
-        }
         if (connManager == null) {
             throw new IllegalArgumentException("Client connection manager may not be null");
         }
@@ -153,7 +153,10 @@ public class MainRequestExecutor impleme
         }
         this.authenticator      = new HttpAuthenticator();
         this.requestExec        = new HttpRequestExecutor();
-        this.httpProcessor      = httpProcessor;
+        this.proxyHttpProcessor = new ImmutableHttpProcessor(new HttpRequestInterceptor[]
{
+                new RequestClientConnControl(),
+                new RequestUserAgent()
+        } );
         this.connManager        = connManager;
         this.reuseStrategy      = reuseStrategy;
         this.keepAliveStrategy  = keepAliveStrategy;
@@ -187,7 +190,11 @@ public class MainRequestExecutor impleme
             proxyAuthState = new AuthState();
         }
 
-        Header[] origheaders = request.getAllHeaders();
+        String userinfo = request.getURI().getUserInfo();
+        if (userinfo != null) {
+            targetAuthState.update(
+                    new BasicScheme(), new UsernamePasswordCredentials(userinfo));
+        }
 
         Object userToken = context.getAttribute(ClientContext.USER_TOKEN);
 
@@ -261,25 +268,26 @@ public class MainRequestExecutor impleme
                     throw new RequestAbortedException("Request aborted");
                 }
 
-                String userinfo = request.getURI().getUserInfo();
-                if (userinfo != null) {
-                    targetAuthState.update(
-                            new BasicScheme(), new UsernamePasswordCredentials(userinfo));
-                }
-
                 if (this.log.isDebugEnabled()) {
                     this.log.debug("Executing request " + request.getRequestLine());
                 }
 
-                // Run request protocol interceptors
-                requestExec.preProcess(request, httpProcessor, context);
+                if (!request.containsHeader(AUTH.WWW_AUTH_RESP)) {
+                    if (this.log.isDebugEnabled()) {
+                        this.log.debug("Target auth state: " + targetAuthState.getState());
+                    }
+                    this.authenticator.generateAuthResponse(request, targetAuthState, context);
+                }
+                if (!request.containsHeader(AUTH.PROXY_AUTH_RESP) && !route.isTunnelled())
{
+                    if (this.log.isDebugEnabled()) {
+                        this.log.debug("Proxy auth state: " + proxyAuthState.getState());
+                    }
+                    this.authenticator.generateAuthResponse(request, proxyAuthState, context);
+                }
 
                 response = requestExec.execute(request, managedConn, context);
                 response.setParams(params);
 
-                // Run response protocol interceptors
-                requestExec.postProcess(response, httpProcessor, context);
-
                 // The connection is in or can be brought to a re-usable state.
                 if (reuseStrategy.keepAlive(response, context)) {
                     // Set the idle duration of this connection
@@ -322,8 +330,9 @@ public class MainRequestExecutor impleme
                             targetAuthState.reset();
                         }
                     }
-                    // discard all headers and retry request
-                    request.setHeaders(origheaders);
+                    // discard previous auth headers
+                    request.removeHeaders(AUTH.WWW_AUTH_RESP);
+                    request.removeHeaders(AUTH.PROXY_AUTH_RESP);
                 } else {
                     break;
                 }
@@ -447,23 +456,21 @@ public class MainRequestExecutor impleme
         HttpHost proxy = route.getProxyHost();
         HttpResponse response = null;
 
+        HttpRequest connect = createConnectRequest(route, context);
+        connect.setParams(this.params);
+
+        this.requestExec.preProcess(connect, this.proxyHttpProcessor, context);
+
         for (;;) {
             if (!managedConn.isOpen()) {
                 managedConn.open(route, context, this.params);
             }
 
-            HttpRequest connect = createConnectRequest(route, context);
-            connect.setParams(this.params);
-
-            // Populate the execution context
-            context.setAttribute(ExecutionContext.HTTP_REQUEST, connect);
-
-            this.requestExec.preProcess(connect, this.httpProcessor, context);
+            connect.removeHeaders(AUTH.PROXY_AUTH_RESP);
+            this.authenticator.generateAuthResponse(connect, proxyAuthState, context);
 
             response = this.requestExec.execute(connect, managedConn, context);
-
             response.setParams(this.params);
-            this.requestExec.postProcess(response, this.httpProcessor, context);
 
             int status = response.getStatusLine().getStatusCode();
             if (status < 200) {
@@ -474,7 +481,7 @@ public class MainRequestExecutor impleme
             if (HttpClientParams.isAuthenticating(this.params)) {
                 if (this.authenticator.isAuthenticationRequested(proxy, response,
                         this.proxyAuthStrategy, proxyAuthState, context)) {
-                    if (this.authenticator.authenticate(proxy, response,
+                    if (this.authenticator.handleAuthChallenge(proxy, response,
                             this.proxyAuthStrategy, proxyAuthState, context)) {
                         // Retry request
                         if (this.reuseStrategy.keepAlive(response, context)) {
@@ -592,13 +599,13 @@ public class MainRequestExecutor impleme
             }
             if (this.authenticator.isAuthenticationRequested(target, response,
                     this.targetAuthStrategy, targetAuthState, context)) {
-                return this.authenticator.authenticate(target, response,
+                return this.authenticator.handleAuthChallenge(target, response,
                         this.targetAuthStrategy, targetAuthState, context);
             }
             HttpHost proxy = route.getProxyHost();
             if (this.authenticator.isAuthenticationRequested(proxy, response,
                     this.proxyAuthStrategy, proxyAuthState, context)) {
-                return this.authenticator.authenticate(proxy, response,
+                return this.authenticator.handleAuthChallenge(proxy, response,
                         this.proxyAuthStrategy, proxyAuthState, context);
             }
         }



Mime
View raw message