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/17 11:33:42 UTC

[httpcomponents-core] branch HTTPCORE-705 updated: HTTPCORE-705: default 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 HTTPCORE-705
in repository https://gitbox.apache.org/repos/asf/httpcomponents-core.git


The following commit(s) were added to refs/heads/HTTPCORE-705 by this push:
     new d919529  HTTPCORE-705: default ConnectionReuseStrategy to use protocol version of the response message by default and that of the execution context as a fallback
d919529 is described below

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

    HTTPCORE-705: default 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 +-
 .../hc/core5/http/impl/TestDefaultConnectionReuseStrategy.java | 10 +++++-----
 2 files changed, 6 insertions(+), 6 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 9252f7b..a197d46 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
@@ -100,8 +100,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");
 
@@ -110,8 +110,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");
         Assert.assertFalse(reuseStrategy.keepAlive(null, response, context));
     }
@@ -126,8 +126,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");
         Assert.assertFalse(reuseStrategy.keepAlive(null, response, context));
@@ -136,8 +136,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);
         Assert.assertFalse(reuseStrategy.keepAlive(null, response, context));
@@ -225,8 +225,8 @@ 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");
+        response.setVersion(HttpVersion.HTTP_1_0);
         Assert.assertFalse(reuseStrategy.keepAlive(null, response, context));
     }