hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r231509 - in /jakarta/httpclient/trunk/http-common/src/java/org/apache/http: executor/HttpExecutionContext.java protocol/HttpContext.java protocol/ResponseConnControl.java protocol/ResponseContent.java
Date Thu, 11 Aug 2005 20:33:48 GMT
Author: olegk
Date: Thu Aug 11 13:33:42 2005
New Revision: 231509

URL: http://svn.apache.org/viewcvs?rev=231509&view=rev
Log:
Added connection control response interceptor

Added:
    jakarta/httpclient/trunk/http-common/src/java/org/apache/http/protocol/ResponseConnControl.java
  (with props)
Modified:
    jakarta/httpclient/trunk/http-common/src/java/org/apache/http/executor/HttpExecutionContext.java
    jakarta/httpclient/trunk/http-common/src/java/org/apache/http/protocol/HttpContext.java
    jakarta/httpclient/trunk/http-common/src/java/org/apache/http/protocol/ResponseContent.java

Modified: jakarta/httpclient/trunk/http-common/src/java/org/apache/http/executor/HttpExecutionContext.java
URL: http://svn.apache.org/viewcvs/jakarta/httpclient/trunk/http-common/src/java/org/apache/http/executor/HttpExecutionContext.java?rev=231509&r1=231508&r2=231509&view=diff
==============================================================================
--- jakarta/httpclient/trunk/http-common/src/java/org/apache/http/executor/HttpExecutionContext.java
(original)
+++ jakarta/httpclient/trunk/http-common/src/java/org/apache/http/executor/HttpExecutionContext.java
Thu Aug 11 13:33:42 2005
@@ -45,8 +45,6 @@
  */
 public class HttpExecutionContext implements HttpContext {
     
-    public static final String HTTP_REQUEST     = "http.request"; 
-    public static final String HTTP_CONNECTION  = "http.connection"; 
     public static final String HTTP_TARGET_HOST = "http.target_host"; 
     public static final String HTTP_PROXY_HOST  = "http.proxy_host"; 
     public static final String HTTP_REQ_SENT    = "http.request_sent"; 

Modified: jakarta/httpclient/trunk/http-common/src/java/org/apache/http/protocol/HttpContext.java
URL: http://svn.apache.org/viewcvs/jakarta/httpclient/trunk/http-common/src/java/org/apache/http/protocol/HttpContext.java?rev=231509&r1=231508&r2=231509&view=diff
==============================================================================
--- jakarta/httpclient/trunk/http-common/src/java/org/apache/http/protocol/HttpContext.java
(original)
+++ jakarta/httpclient/trunk/http-common/src/java/org/apache/http/protocol/HttpContext.java
Thu Aug 11 13:33:42 2005
@@ -40,6 +40,10 @@
  */
 public interface HttpContext {
 
+    public static final String HTTP_CONNECTION  = "http.connection"; 
+    public static final String HTTP_REQUEST     = "http.request"; 
+    public static final String HTTP_RESPONSE    = "http.response"; 
+    
     Object getAttribute(String id);
 
     void setAttribute(String id, Object obj);

Added: jakarta/httpclient/trunk/http-common/src/java/org/apache/http/protocol/ResponseConnControl.java
URL: http://svn.apache.org/viewcvs/jakarta/httpclient/trunk/http-common/src/java/org/apache/http/protocol/ResponseConnControl.java?rev=231509&view=auto
==============================================================================
--- jakarta/httpclient/trunk/http-common/src/java/org/apache/http/protocol/ResponseConnControl.java
(added)
+++ jakarta/httpclient/trunk/http-common/src/java/org/apache/http/protocol/ResponseConnControl.java
Thu Aug 11 13:33:42 2005
@@ -0,0 +1,101 @@
+/*
+ * $HeadURL$
+ * $Revision$
+ * $Date$
+ *
+ * ====================================================================
+ *
+ *  Copyright 1999-2004 The Apache Software Foundation
+ *
+ *  Licensed 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.protocol;
+
+import java.io.IOException;
+
+import org.apache.http.Header;
+import org.apache.http.HttpEntity;
+import org.apache.http.HttpException;
+import org.apache.http.HttpMutableResponse;
+import org.apache.http.HttpRequest;
+import org.apache.http.HttpResponseInterceptor;
+import org.apache.http.HttpStatus;
+import org.apache.http.HttpVersion;
+
+/**
+ * <p>
+ * </p>
+ * @author <a href="mailto:oleg at ural.ru">Oleg Kalnichevski</a>
+ *
+ * @version $Revision$
+ * 
+ * @since 4.0
+ */
+public class ResponseConnControl implements HttpResponseInterceptor {
+
+    private static final String CONN_DIRECTIVE = "Connection";
+
+    private static final String CONN_CLOSE = "Close";
+    
+    public ResponseConnControl() {
+        super();
+    }
+    
+    public void process(final HttpMutableResponse response, final HttpContext context) 
+        throws HttpException, IOException {
+        if (response == null) {
+            throw new IllegalArgumentException("HTTP request may not be null");
+        }
+        if (context == null) {
+            throw new IllegalArgumentException("HTTP context may not be null");
+        }
+        // Always drop connection after certain type of responses
+        int status = response.getStatusLine().getStatusCode();
+        if (status == HttpStatus.SC_BAD_REQUEST ||
+        		status == HttpStatus.SC_REQUEST_TIMEOUT ||
+        		status == HttpStatus.SC_LENGTH_REQUIRED ||
+        		status == HttpStatus.SC_REQUEST_TOO_LONG ||
+        		status == HttpStatus.SC_REQUEST_URI_TOO_LONG ||
+        		status == HttpStatus.SC_INTERNAL_SERVER_ERROR ||
+        		status == HttpStatus.SC_SERVICE_UNAVAILABLE ||
+        		status == HttpStatus.SC_NOT_IMPLEMENTED) {
+            response.setHeader(new Header(CONN_DIRECTIVE, CONN_CLOSE, true));
+            return;
+        }
+        // Always drop connection for HTTP/1.0 responses and below
+        // if the content body cannot be correctly delimited
+        HttpVersion ver = response.getStatusLine().getHttpVersion();
+        if (ver.lessEquals(HttpVersion.HTTP_1_0)) {
+            HttpEntity entity = response.getEntity();
+            if (entity != null && entity.getContentLength() < 0) {
+            	response.setHeader(new Header(CONN_DIRECTIVE, CONN_CLOSE, true));
+                return;
+            }
+        }
+        // Drop connection if requested by the client
+        HttpRequest request = (HttpRequest) context.getAttribute(HttpContext.HTTP_REQUEST);
+        Header header = request.getFirstHeader(CONN_DIRECTIVE);
+        if (header != null) {
+        	response.setHeader(new Header(CONN_DIRECTIVE, header.getValue(), true));
+        }
+    }
+    
+}

Propchange: jakarta/httpclient/trunk/http-common/src/java/org/apache/http/protocol/ResponseConnControl.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jakarta/httpclient/trunk/http-common/src/java/org/apache/http/protocol/ResponseConnControl.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: jakarta/httpclient/trunk/http-common/src/java/org/apache/http/protocol/ResponseConnControl.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: jakarta/httpclient/trunk/http-common/src/java/org/apache/http/protocol/ResponseContent.java
URL: http://svn.apache.org/viewcvs/jakarta/httpclient/trunk/http-common/src/java/org/apache/http/protocol/ResponseContent.java?rev=231509&r1=231508&r2=231509&view=diff
==============================================================================
--- jakarta/httpclient/trunk/http-common/src/java/org/apache/http/protocol/ResponseContent.java
(original)
+++ jakarta/httpclient/trunk/http-common/src/java/org/apache/http/protocol/ResponseContent.java
Thu Aug 11 13:33:42 2005
@@ -53,10 +53,8 @@
     private static final String CONTENT_LEN  = "Content-Length";
     private static final String CONTENT_TYPE = "Content-Type";
     private static final String CONTENT_ENC = "Content-Encoding";
-    private static final String CONN_DIRECTIVE = "Connection";
 
     private static final String CHUNK_CODING = "chunked";
-    private static final String CONN_CLOSE = "close";
     
     public ResponseContent() {
         super();
@@ -78,8 +76,6 @@
                 response.setHeader(new Header(CONTENT_LEN, 
                         Long.toString(entity.getContentLength()), true));
                 response.removeHeaders(TRANSFER_ENC);
-            } else {
-                response.setHeader(new Header(CONN_DIRECTIVE, CONN_CLOSE, true));
             }
             // Specify a content type if known
             if (entity.getContentType() != null) {



Mime
View raw message