You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hc.apache.org by ol...@apache.org on 2011/11/22 14:45:53 UTC

svn commit: r1204991 - in /httpcomponents/httpcore/trunk: RELEASE_NOTES.txt httpcore/src/main/java/org/apache/http/protocol/ResponseConnControl.java httpcore/src/test/java/org/apache/http/protocol/TestStandardInterceptors.java

Author: olegk
Date: Tue Nov 22 13:45:52 2011
New Revision: 1204991

URL: http://svn.apache.org/viewvc?rev=1204991&view=rev
Log:
HTTPCORE-281: ResponseConnControl protocol interceptor does not correctly populate connection persistence control headers when sending a HTTP/1.1 response message in response to a HTTP/1.0 request message.
Contributed by William R. Speirs <bill.speirs at gmail.com>

Modified:
    httpcomponents/httpcore/trunk/RELEASE_NOTES.txt
    httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/protocol/ResponseConnControl.java
    httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/protocol/TestStandardInterceptors.java

Modified: httpcomponents/httpcore/trunk/RELEASE_NOTES.txt
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/RELEASE_NOTES.txt?rev=1204991&r1=1204990&r2=1204991&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/RELEASE_NOTES.txt (original)
+++ httpcomponents/httpcore/trunk/RELEASE_NOTES.txt Tue Nov 22 13:45:52 2011
@@ -1,6 +1,11 @@
 Changes since Release 4.2-ALPHA2
 -------------------
 
+* [HTTPCORE-281] ResponseConnControl protocol interceptor does not correctly populate connection
+  persistence control headers when sending a HTTP/1.1 response message in response to a HTTP/1.0 
+  request message.
+  Contributed by William R. Speirs <bill.speirs at gmail.com>
+
 * [HTTPCORE-282] The default value of the internal event mask of newly created non-blocking I/O 
   is not correctly initialized, which causes the READ interest bit to get cleared in the interest 
   op queuing mode unless the event mask is explicitly reset.

Modified: httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/protocol/ResponseConnControl.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/protocol/ResponseConnControl.java?rev=1204991&r1=1204990&r2=1204991&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/protocol/ResponseConnControl.java (original)
+++ httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/protocol/ResponseConnControl.java Tue Nov 22 13:45:52 2011
@@ -86,13 +86,15 @@ public class ResponseConnControl impleme
                 return;
             }
         }
-        // Drop connection if requested by the client
+        // Drop connection if requested by the client or request was <= 1.0
         HttpRequest request = (HttpRequest)
             context.getAttribute(ExecutionContext.HTTP_REQUEST);
         if (request != null) {
             Header header = request.getFirstHeader(HTTP.CONN_DIRECTIVE);
             if (header != null) {
                 response.setHeader(HTTP.CONN_DIRECTIVE, header.getValue());
+            } else if (request.getProtocolVersion().lessEquals(HttpVersion.HTTP_1_0)) {
+                response.setHeader(HTTP.CONN_DIRECTIVE, HTTP.CONN_CLOSE);
             }
         }
     }

Modified: httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/protocol/TestStandardInterceptors.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/protocol/TestStandardInterceptors.java?rev=1204991&r1=1204990&r2=1204991&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/protocol/TestStandardInterceptors.java (original)
+++ httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/protocol/TestStandardInterceptors.java Tue Nov 22 13:45:52 2011
@@ -621,6 +621,22 @@ public class TestStandardInterceptors {
     }
 
     @Test
+    public void testResponseConnControl10Client11Response() throws Exception {
+        HttpContext context = new BasicHttpContext(null);
+        BasicHttpRequest request = new BasicHttpRequest("GET", "/", HttpVersion.HTTP_1_0);
+        context.setAttribute(ExecutionContext.HTTP_REQUEST, request);
+
+        HttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_OK, "OK");
+        StringEntity entity = new StringEntity("whatever");
+        response.setEntity(entity);
+        ResponseConnControl interceptor = new ResponseConnControl();
+        interceptor.process(response, context);
+        Header header = response.getFirstHeader(HTTP.CONN_DIRECTIVE);
+        Assert.assertNotNull(header);
+        Assert.assertEquals(HTTP.CONN_CLOSE, header.getValue());
+    }
+
+    @Test
     public void testResponseConnControlStatusCode() throws Exception {
         HttpContext context = new BasicHttpContext(null);
         BasicHttpRequest request = new BasicHttpRequest("GET", "/");