hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r1231228 - in /httpcomponents/httpcore/trunk/httpcore/src: main/java/org/apache/http/protocol/ResponseConnControl.java test/java/org/apache/http/protocol/TestStandardInterceptors.java
Date Fri, 13 Jan 2012 18:30:20 GMT
Author: olegk
Date: Fri Jan 13 18:30:20 2012
New Revision: 1231228

URL: http://svn.apache.org/viewvc?rev=1231228&view=rev
Log:
Explicit 'connection: close' should take precedence over the default connection keep-alive
logic

Modified:
    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/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=1231228&r1=1231227&r2=1231228&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
Fri Jan 13 18:30:20 2012
@@ -75,6 +75,11 @@ public class ResponseConnControl impleme
             response.setHeader(HTTP.CONN_DIRECTIVE, HTTP.CONN_CLOSE);
             return;
         }
+        Header explicit = response.getFirstHeader(HTTP.CONN_DIRECTIVE);
+        if (explicit != null && HTTP.CONN_CLOSE.equalsIgnoreCase(explicit.getValue()))
{
+            // Connection persistence explicitly disabled
+            return;
+        }
         // Always drop connection for HTTP/1.0 responses and below
         // if the content body cannot be correctly delimited
         HttpEntity entity = response.getEntity();

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=1231228&r1=1231227&r2=1231228&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
Fri Jan 13 18:30:20 2012
@@ -666,6 +666,24 @@ public class TestStandardInterceptors {
     }
 
     @Test
+    public void testResponseConnControlExplicitClose() throws Exception {
+        HttpContext context = new BasicHttpContext(null);
+        BasicHttpRequest request = new BasicHttpRequest("GET", "/");
+        request.addHeader(new BasicHeader(HTTP.CONN_DIRECTIVE, HTTP.CONN_KEEP_ALIVE));
+        context.setAttribute(ExecutionContext.HTTP_REQUEST, request);
+
+        ResponseConnControl interceptor = new ResponseConnControl();
+
+        BasicHttpResponse response = new BasicHttpResponse(
+                HttpVersion.HTTP_1_1, 200, "OK");
+        response.setHeader(HTTP.CONN_DIRECTIVE, HTTP.CONN_CLOSE);
+        interceptor.process(response, context);
+        Header header = response.getFirstHeader(HTTP.CONN_DIRECTIVE);
+        Assert.assertNotNull(header);
+        Assert.assertEquals(HTTP.CONN_CLOSE, header.getValue());
+    }
+
+    @Test
     public void testResponseConnControlHostInvalidInput() throws Exception {
         ResponseConnControl interceptor = new ResponseConnControl();
         try {



Mime
View raw message