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 2021/12/19 10:04:40 UTC

[httpcomponents-core] 03/03: HTTPCORE-705: ConnectionReuseStrategy to use protocol version of the response message by default and that of the execution context as a fallback

This is an automated email from the ASF dual-hosted git repository.

olegk pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/httpcomponents-core.git

commit c4a2881a543df5f997c8a3a22e1422962636a9fe
Author: Oleg Kalnichevski <ol...@apache.org>
AuthorDate: Fri Dec 17 12:24:06 2021 +0100

    HTTPCORE-705: ConnectionReuseStrategy to use protocol version of the response message by default and that of the execution context as a fallback
---
 .../hc/core5/http/impl/DefaultConnectionReuseStrategy.java   |  2 +-
 .../core5/http/impl/TestDefaultConnectionReuseStrategy.java  | 12 ++++++------
 2 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/httpcore5/src/main/java/org/apache/hc/core5/http/impl/DefaultConnectionReuseStrategy.java b/httpcore5/src/main/java/org/apache/hc/core5/http/impl/DefaultConnectionReuseStrategy.java
index 0231bcb..10ca317 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/http/impl/DefaultConnectionReuseStrategy.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/http/impl/DefaultConnectionReuseStrategy.java
@@ -133,7 +133,7 @@ public class DefaultConnectionReuseStrategy implements ConnectionReuseStrategy {
             headerIterator = response.headerIterator("Proxy-Connection");
         }
 
-        final ProtocolVersion ver = context.getProtocolVersion();
+        final ProtocolVersion ver = response.getVersion() != null ? response.getVersion() : context.getProtocolVersion();
         if (headerIterator.hasNext()) {
             if (ver.greaterEquals(HttpVersion.HTTP_1_1)) {
                 final Iterator<String> it = new BasicTokenIterator(headerIterator);
diff --git a/httpcore5/src/test/java/org/apache/hc/core5/http/impl/TestDefaultConnectionReuseStrategy.java b/httpcore5/src/test/java/org/apache/hc/core5/http/impl/TestDefaultConnectionReuseStrategy.java
index fd5f375..208508b 100644
--- a/httpcore5/src/test/java/org/apache/hc/core5/http/impl/TestDefaultConnectionReuseStrategy.java
+++ b/httpcore5/src/test/java/org/apache/hc/core5/http/impl/TestDefaultConnectionReuseStrategy.java
@@ -101,8 +101,8 @@ public class TestDefaultConnectionReuseStrategy {
     @Test
     public void testExplicitKeepAlive() throws Exception {
         // Use HTTP 1.0
-        context.setProtocolVersion(HttpVersion.HTTP_1_0);
         final HttpResponse response = new BasicHttpResponse(200, "OK");
+        response.setVersion(HttpVersion.HTTP_1_0);
         response.addHeader("Content-Length", "10");
         response.addHeader("Connection", "keep-alive");
 
@@ -111,8 +111,8 @@ public class TestDefaultConnectionReuseStrategy {
 
     @Test
     public void testHTTP10Default() throws Exception {
-        context.setProtocolVersion(HttpVersion.HTTP_1_0);
         final HttpResponse response = new BasicHttpResponse(200, "OK");
+        response.setVersion(HttpVersion.HTTP_1_0);
         response.addHeader("Content-Length", "10");
         Assertions.assertFalse(reuseStrategy.keepAlive(null, response, context));
     }
@@ -127,8 +127,8 @@ public class TestDefaultConnectionReuseStrategy {
     @Test
     public void testBrokenConnectionDirective1() throws Exception {
         // Use HTTP 1.0
-        context.setProtocolVersion(HttpVersion.HTTP_1_0);
         final HttpResponse response = new BasicHttpResponse(200, "OK");
+        response.setVersion(HttpVersion.HTTP_1_0);
         response.addHeader("Content-Length", "10");
         response.addHeader("Connection", "keep--alive");
         Assertions.assertFalse(reuseStrategy.keepAlive(null, response, context));
@@ -137,8 +137,8 @@ public class TestDefaultConnectionReuseStrategy {
     @Test
     public void testBrokenConnectionDirective2() throws Exception {
         // Use HTTP 1.0
-        context.setProtocolVersion(HttpVersion.HTTP_1_0);
         final HttpResponse response = new BasicHttpResponse(200, "OK");
+        response.setVersion(HttpVersion.HTTP_1_0);
         response.addHeader("Content-Length", "10");
         response.addHeader("Connection", null);
         Assertions.assertFalse(reuseStrategy.keepAlive(null, response, context));
@@ -226,9 +226,9 @@ public class TestDefaultConnectionReuseStrategy {
     @Test
     public void testNoContentResponseHttp10() throws Exception {
         // Use HTTP 1.0
-        context.setProtocolVersion(HttpVersion.HTTP_1_0);
         final HttpResponse response = new BasicHttpResponse(HttpStatus.SC_NO_CONTENT, "No Content");
-        Assertions.assertFalse(reuseStrategy.keepAlive(null, response, context));
+        response.setVersion(HttpVersion.HTTP_1_0);
+        Assert.assertFalse(reuseStrategy.keepAlive(null, response, context));
     }
 
     @Test