hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r783453 - in /httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http: client/protocol/RequestClientConnControl.java impl/client/DefaultHttpClient.java
Date Wed, 10 Jun 2009 19:13:26 GMT
Author: olegk
Date: Wed Jun 10 19:13:24 2009
New Revision: 783453

URL: http://svn.apache.org/viewvc?rev=783453&view=rev
Log:
Added a more advanced protocol interceptor for generating Connection and Proxy-Connection
request headers

Added:
    httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/protocol/RequestClientConnControl.java
  (with props)
Modified:
    httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/DefaultHttpClient.java

Added: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/protocol/RequestClientConnControl.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/protocol/RequestClientConnControl.java?rev=783453&view=auto
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/protocol/RequestClientConnControl.java
(added)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/protocol/RequestClientConnControl.java
Wed Jun 10 19:13:24 2009
@@ -0,0 +1,93 @@
+/*
+ * $HeadURL$
+ * $Revision$
+ * $Date$
+ *
+ * ====================================================================
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.http.client.protocol;
+
+import java.io.IOException;
+
+import org.apache.http.HttpException;
+import org.apache.http.HttpRequest;
+import org.apache.http.HttpRequestInterceptor;
+import org.apache.http.conn.ManagedClientConnection;
+import org.apache.http.conn.routing.HttpRoute;
+import org.apache.http.protocol.ExecutionContext;
+import org.apache.http.protocol.HTTP;
+import org.apache.http.protocol.HttpContext;
+
+/**
+ * This protocol interceptor is responsible for adding <code>Connection</code>

+ * or <code>Proxy-Connection</code> headers to the outgoing requests, which 
+ * is essential for managing persistence of <code>HTTP/1.0</code> connections.

+ * 
+ * @since 4.0
+ */
+public class RequestClientConnControl implements HttpRequestInterceptor {
+
+    private static final String PROXY_CONN_DIRECTIVE = "Proxy-Connection";
+    
+    public RequestClientConnControl() {
+        super();
+    }
+    
+    public void process(final HttpRequest request, final HttpContext context) 
+            throws HttpException, IOException {
+        if (request == null) {
+            throw new IllegalArgumentException("HTTP request may not be null");
+        }
+
+        String method = request.getRequestLine().getMethod();
+        if (method.equalsIgnoreCase("CONNECT")) {
+            request.setHeader(PROXY_CONN_DIRECTIVE, HTTP.CONN_KEEP_ALIVE);
+            return;
+        }
+        
+        // Obtain the client connection (required)
+        ManagedClientConnection conn = (ManagedClientConnection) context.getAttribute(
+                ExecutionContext.HTTP_CONNECTION);
+        if (conn == null) {
+            throw new IllegalStateException("Client connection not specified in HTTP context");
+        }
+
+        HttpRoute route = conn.getRoute();
+        
+        if (route.getHopCount() == 1 || route.isTunnelled()) {
+            if (!request.containsHeader(HTTP.CONN_DIRECTIVE)) {
+                request.addHeader(HTTP.CONN_DIRECTIVE, HTTP.CONN_KEEP_ALIVE);
+            }
+        }
+        if (route.getHopCount() == 2 && !route.isTunnelled()) {
+            if (!request.containsHeader(PROXY_CONN_DIRECTIVE)) {
+                request.addHeader(PROXY_CONN_DIRECTIVE, HTTP.CONN_KEEP_ALIVE);
+            }
+        }
+    }
+    
+}

Propchange: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/protocol/RequestClientConnControl.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/protocol/RequestClientConnControl.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/protocol/RequestClientConnControl.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/DefaultHttpClient.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/DefaultHttpClient.java?rev=783453&r1=783452&r2=783453&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/DefaultHttpClient.java
(original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/DefaultHttpClient.java
Wed Jun 10 19:13:24 2009
@@ -47,6 +47,7 @@
 import org.apache.http.client.params.CookiePolicy;
 import org.apache.http.client.protocol.ClientContext;
 import org.apache.http.client.protocol.RequestAddCookies;
+import org.apache.http.client.protocol.RequestClientConnControl;
 import org.apache.http.client.protocol.RequestDefaultHeaders;
 import org.apache.http.client.protocol.RequestProxyAuthentication;
 import org.apache.http.client.protocol.RequestTargetAuthentication;
@@ -79,7 +80,6 @@
 import org.apache.http.protocol.HTTP;
 import org.apache.http.protocol.HttpContext;
 import org.apache.http.protocol.HttpRequestExecutor;
-import org.apache.http.protocol.RequestConnControl;
 import org.apache.http.protocol.RequestContent;
 import org.apache.http.protocol.RequestExpectContinue;
 import org.apache.http.protocol.RequestTargetHost;
@@ -98,7 +98,7 @@
  * <li>{@link RequestDefaultHeaders}</li>
  * <li>{@link RequestContent}</li>
  * <li>{@link RequestTargetHost}</li>
- * <li>{@link RequestConnControl}</li>
+ * <li>{@link RequestClientConnControl}</li>
  * <li>{@link RequestUserAgent}</li>
  * <li>{@link RequestExpectContinue}</li>
  * <li>{@link RequestAddCookies}</li>
@@ -328,7 +328,7 @@
         httpproc.addInterceptor(new RequestContent());
         httpproc.addInterceptor(new RequestTargetHost());
         // Recommended protocol interceptors
-        httpproc.addInterceptor(new RequestConnControl());
+        httpproc.addInterceptor(new RequestClientConnControl());
         httpproc.addInterceptor(new RequestUserAgent());
         httpproc.addInterceptor(new RequestExpectContinue());
         // HTTP state management interceptors



Mime
View raw message