hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r685136 - in /httpcomponents/httpclient/trunk: ./ module-client/src/main/java/org/apache/http/client/protocol/ module-client/src/main/java/org/apache/http/impl/client/
Date Tue, 12 Aug 2008 12:53:50 GMT
Author: olegk
Date: Tue Aug 12 05:53:49 2008
New Revision: 685136

URL: http://svn.apache.org/viewvc?rev=685136&view=rev
Log:
HTTPCLIENT-790: Protocol interceptors not called when executing CONNECT methods

Modified:
    httpcomponents/httpclient/trunk/RELEASE_NOTES.txt
    httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/client/protocol/RequestAddCookies.java
    httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/client/protocol/RequestDefaultHeaders.java
    httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/client/protocol/RequestTargetAuthentication.java
    httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/client/DefaultHttpClient.java
    httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/client/DefaultRequestDirector.java

Modified: httpcomponents/httpclient/trunk/RELEASE_NOTES.txt
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/RELEASE_NOTES.txt?rev=685136&r1=685135&r2=685136&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/RELEASE_NOTES.txt (original)
+++ httpcomponents/httpclient/trunk/RELEASE_NOTES.txt Tue Aug 12 05:53:49 2008
@@ -1,7 +1,11 @@
 Changes since 4.0 Alpha 4
 -------------------
 
-* [HTTPCLIENT-668] Do not use static loggers
+* [HTTPCLIENT-790] Protocol interceptors are now correctly invoked when 
+  executing CONNECT methods.
+  Contributed by Oleg Kalnichevski <olegk at apache.org>
+
+* [HTTPCLIENT-668] Do not use static loggers.
   Contributed by Oleg Kalnichevski <olegk at apache.org>
 
 * [HTTPCLIENT-781] Respect Keep-Alive header's timeout value.

Modified: httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/client/protocol/RequestAddCookies.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/client/protocol/RequestAddCookies.java?rev=685136&r1=685135&r2=685136&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/client/protocol/RequestAddCookies.java
(original)
+++ httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/client/protocol/RequestAddCookies.java
Tue Aug 12 05:53:49 2008
@@ -84,6 +84,11 @@
             throw new IllegalArgumentException("HTTP context may not be null");
         }
         
+        String method = request.getRequestLine().getMethod();
+        if (method.equalsIgnoreCase("CONNECT")) {
+            return;
+        }
+        
         // Obtain cookie store
         CookieStore cookieStore = (CookieStore) context.getAttribute(
                 ClientContext.COOKIE_STORE);

Modified: httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/client/protocol/RequestDefaultHeaders.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/client/protocol/RequestDefaultHeaders.java?rev=685136&r1=685135&r2=685136&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/client/protocol/RequestDefaultHeaders.java
(original)
+++ httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/client/protocol/RequestDefaultHeaders.java
Tue Aug 12 05:53:49 2008
@@ -61,6 +61,12 @@
         if (request == null) {
             throw new IllegalArgumentException("HTTP request may not be null");
         }
+        
+        String method = request.getRequestLine().getMethod();
+        if (method.equalsIgnoreCase("CONNECT")) {
+            return;
+        }
+        
         // Add default headers
         Collection<?> defHeaders = (Collection<?>) request.getParams().getParameter(
                 ClientPNames.DEFAULT_HEADERS);

Modified: httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/client/protocol/RequestTargetAuthentication.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/client/protocol/RequestTargetAuthentication.java?rev=685136&r1=685135&r2=685136&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/client/protocol/RequestTargetAuthentication.java
(original)
+++ httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/client/protocol/RequestTargetAuthentication.java
Tue Aug 12 05:53:49 2008
@@ -69,6 +69,11 @@
             throw new IllegalArgumentException("HTTP context may not be null");
         }
 
+        String method = request.getRequestLine().getMethod();
+        if (method.equalsIgnoreCase("CONNECT")) {
+            return;
+        }
+        
         if (request.containsHeader(AUTH.WWW_AUTH_RESP)) {
             return;
         }

Modified: httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/client/DefaultHttpClient.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/client/DefaultHttpClient.java?rev=685136&r1=685135&r2=685136&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/client/DefaultHttpClient.java
(original)
+++ httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/client/DefaultHttpClient.java
Tue Aug 12 05:53:49 2008
@@ -31,7 +31,12 @@
 
 package org.apache.http.impl.client;
 
+import java.io.IOException;
+
 import org.apache.http.ConnectionReuseStrategy;
+import org.apache.http.HttpException;
+import org.apache.http.HttpRequest;
+import org.apache.http.HttpRequestInterceptor;
 import org.apache.http.HttpVersion;
 import org.apache.http.auth.AuthSchemeRegistry;
 import org.apache.http.client.AuthenticationHandler;
@@ -266,9 +271,9 @@
         httpproc.addInterceptor(new RequestDefaultHeaders());
         // Required protocol interceptors
         httpproc.addInterceptor(new RequestContent());
-        httpproc.addInterceptor(new RequestTargetHost());
+        httpproc.addInterceptor(new IgnoreConnectMethod(new RequestTargetHost()));
         // Recommended protocol interceptors
-        httpproc.addInterceptor(new RequestConnControl());
+        httpproc.addInterceptor(new IgnoreConnectMethod(new RequestConnControl()));
         httpproc.addInterceptor(new RequestUserAgent());
         httpproc.addInterceptor(new RequestExpectContinue());
         // HTTP state management interceptors
@@ -329,4 +334,26 @@
         return new DefaultUserTokenHandler();
     }
     
+    // FIXME: remove this class when protocol interceptors in HttpCore
+    // are updated to ignore CONNECT methods
+    static class IgnoreConnectMethod implements HttpRequestInterceptor {
+
+        private final HttpRequestInterceptor interceptor;
+        
+        public IgnoreConnectMethod(final HttpRequestInterceptor interceptor) {
+            super();
+            this.interceptor = interceptor;
+        }
+        
+        public void process(
+                final HttpRequest request, 
+                final HttpContext context) throws HttpException, IOException {
+            String method = request.getRequestLine().getMethod();
+            if (!method.equalsIgnoreCase("CONNECT")) {
+                this.interceptor.process(request, context);
+            }
+        }
+        
+    }
+    
 } // class DefaultHttpClient

Modified: httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/client/DefaultRequestDirector.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/client/DefaultRequestDirector.java?rev=685136&r1=685135&r2=685136&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/client/DefaultRequestDirector.java
(original)
+++ httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/client/DefaultRequestDirector.java
Tue Aug 12 05:53:49 2008
@@ -88,7 +88,6 @@
 import org.apache.http.params.HttpParams;
 import org.apache.http.params.HttpProtocolParams;
 import org.apache.http.protocol.ExecutionContext;
-import org.apache.http.protocol.HTTP;
 import org.apache.http.protocol.HttpContext;
 import org.apache.http.protocol.HttpProcessor;
 import org.apache.http.protocol.HttpRequestExecutor;
@@ -385,13 +384,12 @@
                         targetAuthState);
                 context.setAttribute(ClientContext.PROXY_AUTH_STATE,
                         proxyAuthState);
-                
-                // Run request protocol interceptors
-                requestExec.preProcess(wrapper, httpProcessor, context);
-                
                 context.setAttribute(ExecutionContext.HTTP_REQUEST,
                         wrapper);
 
+                // Run request protocol interceptors
+                requestExec.preProcess(wrapper, httpProcessor, context);
+                
                 boolean retrying = true;
                 while (retrying) {
                     // Increment total exec count (with redirects)
@@ -680,29 +678,28 @@
             }
             
             HttpRequest connect = createConnectRequest(route, context);
+            connect.setParams(this.params);
             
-            String agent = HttpProtocolParams.getUserAgent(params);
-            if (agent != null) {
-                connect.addHeader(HTTP.USER_AGENT, agent);
-            }
-            connect.addHeader(HTTP.TARGET_HOST, target.toHostString());
-            
-            AuthScheme authScheme = this.proxyAuthState.getAuthScheme();
-            AuthScope authScope = this.proxyAuthState.getAuthScope();
-            Credentials creds = this.proxyAuthState.getCredentials();
-            if (creds != null) {
-                if (authScope != null || !authScheme.isConnectionBased()) {
-                    try {
-                        connect.addHeader(authScheme.authenticate(creds, connect));
-                    } catch (AuthenticationException ex) {
-                        if (this.log.isErrorEnabled()) {
-                            this.log.error("Proxy authentication error: " + ex.getMessage());
-                        }
-                    }
-                }
-            }
+            // Populate the execution context
+            context.setAttribute(ExecutionContext.HTTP_TARGET_HOST,
+                    target);
+            context.setAttribute(ExecutionContext.HTTP_PROXY_HOST,
+                    proxy);
+            context.setAttribute(ExecutionContext.HTTP_CONNECTION,
+                    managedConn);
+            context.setAttribute(ClientContext.TARGET_AUTH_STATE,
+                    targetAuthState);
+            context.setAttribute(ClientContext.PROXY_AUTH_STATE,
+                    proxyAuthState);
+            context.setAttribute(ExecutionContext.HTTP_REQUEST,
+                    connect);
+            
+            this.requestExec.preProcess(connect, this.httpProcessor, context);
+            
+            response = this.requestExec.execute(connect, this.managedConn, context);
             
-            response = requestExec.execute(connect, this.managedConn, context);
+            response.setParams(this.params);
+            this.requestExec.postProcess(response, this.httpProcessor, context);
             
             int status = response.getStatusLine().getStatusCode();
             if (status < 200) {



Mime
View raw message