hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r1673258 - in /httpcomponents/httpcore/trunk/httpcore/src: main/java/org/apache/http/impl/DefaultConnectionReuseStrategy.java test/java/org/apache/http/impl/TestDefaultConnectionReuseStrategy.java
Date Mon, 13 Apr 2015 18:32:01 GMT
Author: olegk
Date: Mon Apr 13 18:32:00 2015
New Revision: 1673258

URL: http://svn.apache.org/r1673258
Log:
HTTPCORE-397: DefaultConnectionReuseStrategy to take into account request 'Connection: close'
directive

Modified:
    httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/DefaultConnectionReuseStrategy.java
    httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/impl/TestDefaultConnectionReuseStrategy.java

Modified: httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/DefaultConnectionReuseStrategy.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/DefaultConnectionReuseStrategy.java?rev=1673258&r1=1673257&r2=1673258&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/DefaultConnectionReuseStrategy.java
(original)
+++ httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/DefaultConnectionReuseStrategy.java
Mon Apr 13 18:32:00 2015
@@ -78,6 +78,19 @@ public class DefaultConnectionReuseStrat
         Args.notNull(response, "HTTP response");
         Args.notNull(context, "HTTP context");
 
+        if (request != null) {
+            final Header[] connHeaders = request.getHeaders(HttpHeaders.CONNECTION);
+            if (connHeaders.length != 0) {
+                final Iterator<String> ti = new BasicTokenIterator(new BasicHeaderIterator(connHeaders,
null));
+                while (ti.hasNext()) {
+                    final String token = ti.next();
+                    if (HeaderElements.CLOSE.equalsIgnoreCase(token)) {
+                        return false;
+                    }
+                }
+            }
+        }
+
         // Check for a self-terminating entity. If the end of the entity will
         // be indicated by closing the connection, there is no keep-alive.
         final ProtocolVersion ver = response.getStatusLine().getProtocolVersion();

Modified: httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/impl/TestDefaultConnectionReuseStrategy.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/impl/TestDefaultConnectionReuseStrategy.java?rev=1673258&r1=1673257&r2=1673258&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/impl/TestDefaultConnectionReuseStrategy.java
(original)
+++ httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/impl/TestDefaultConnectionReuseStrategy.java
Mon Apr 13 18:32:00 2015
@@ -28,9 +28,11 @@
 package org.apache.http.impl;
 
 import org.apache.http.ConnectionReuseStrategy;
+import org.apache.http.HttpRequest;
 import org.apache.http.HttpResponse;
 import org.apache.http.HttpStatus;
 import org.apache.http.HttpVersion;
+import org.apache.http.message.BasicHttpRequest;
 import org.apache.http.message.BasicHttpResponse;
 import org.apache.http.protocol.BasicHttpContext;
 import org.apache.http.protocol.HttpContext;
@@ -251,5 +253,40 @@ public class TestDefaultConnectionReuseS
         Assert.assertFalse(reuseStrategy.keepAlive(null, response, context));
     }
 
+    @Test
+    public void testRequestExplicitClose() throws Exception {
+        final HttpRequest request = new BasicHttpRequest("GET", "/");
+        request.addHeader("Connection", "close");
+
+        final HttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1, 200, "OK");
+        response.addHeader("Transfer-Encoding", "chunked");
+        response.addHeader("Connection", "keep-alive");
+        Assert.assertFalse(reuseStrategy.keepAlive(request, response, context));
+    }
+
+    @Test
+    public void testRequestNoExplicitClose() throws Exception {
+        final HttpRequest request = new BasicHttpRequest("GET", "/");
+        request.addHeader("Connection", "blah, blah, blah");
+
+        final HttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1, 200, "OK");
+        response.addHeader("Transfer-Encoding", "chunked");
+        response.addHeader("Connection", "keep-alive");
+        Assert.assertTrue(reuseStrategy.keepAlive(request, response, context));
+    }
+
+    @Test
+    public void testRequestExplicitCloseMultipleTokens() throws Exception {
+        final HttpRequest request = new BasicHttpRequest("GET", "/");
+        request.addHeader("Connection", "blah, blah, blah");
+        request.addHeader("Connection", "keep-alive");
+        request.addHeader("Connection", "close");
+
+        final HttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1, 200, "OK");
+        response.addHeader("Transfer-Encoding", "chunked");
+        response.addHeader("Connection", "keep-alive");
+        Assert.assertFalse(reuseStrategy.keepAlive(request, response, context));
+    }
+
 }
 



Mime
View raw message