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/09/18 08:30:07 UTC

[httpcomponents-client] 03/03: HTTPCLIENT-2177: automatically force HTTP/1.1 protocol policy when executing requests via a proxy tunnel

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

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

commit b95b917cb2ba39773e9b3114cd873e8d9f95002d
Author: Oleg Kalnichevski <ol...@apache.org>
AuthorDate: Fri Sep 17 22:38:14 2021 +0200

    HTTPCLIENT-2177: automatically force HTTP/1.1 protocol policy when executing requests via a proxy tunnel
---
 .../http/impl/async/InternalAbstractHttpAsyncClient.java    |  5 +++--
 .../hc/client5/http/impl/async/InternalH2AsyncClient.java   |  3 ++-
 .../hc/client5/http/impl/async/InternalHttpAsyncClient.java | 13 +++++++++++--
 3 files changed, 16 insertions(+), 5 deletions(-)

diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/InternalAbstractHttpAsyncClient.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/InternalAbstractHttpAsyncClient.java
index ca9ffc0..57aec3d 100644
--- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/InternalAbstractHttpAsyncClient.java
+++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/InternalAbstractHttpAsyncClient.java
@@ -142,7 +142,8 @@ abstract class InternalAbstractHttpAsyncClient extends AbstractHttpAsyncClientBa
         }
     }
 
-    abstract AsyncExecRuntime createAsyncExecRuntime(HandlerFactory<AsyncPushConsumer> pushHandlerFactory);
+    abstract AsyncExecRuntime createAsyncExecRuntime(
+            HandlerFactory<AsyncPushConsumer> pushHandlerFactory, HttpRoute route);
 
     abstract HttpRoute determineRoute(HttpHost httpHost, HttpClientContext clientContext) throws HttpException;
 
@@ -182,7 +183,7 @@ abstract class InternalAbstractHttpAsyncClient extends AbstractHttpAsyncClientBa
                     if (LOG.isDebugEnabled()) {
                         LOG.debug("{}: preparing request execution", exchangeId);
                     }
-                    final AsyncExecRuntime execRuntime = createAsyncExecRuntime(pushHandlerFactory);
+                    final AsyncExecRuntime execRuntime = createAsyncExecRuntime(pushHandlerFactory, route);
 
                     setupContext(clientContext);
 
diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/InternalH2AsyncClient.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/InternalH2AsyncClient.java
index 6ebaf66..6841e27 100644
--- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/InternalH2AsyncClient.java
+++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/InternalH2AsyncClient.java
@@ -90,7 +90,8 @@ public final class InternalH2AsyncClient extends InternalAbstractHttpAsyncClient
     }
 
     @Override
-    AsyncExecRuntime createAsyncExecRuntime(final HandlerFactory<AsyncPushConsumer> pushHandlerFactory) {
+    AsyncExecRuntime createAsyncExecRuntime(final HandlerFactory<AsyncPushConsumer> pushHandlerFactory,
+                                            final HttpRoute route) {
         return new InternalH2AsyncExecRuntime(LOG, connPool, pushHandlerFactory);
     }
 
diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/InternalHttpAsyncClient.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/InternalHttpAsyncClient.java
index c2b7c5c..3ab0862 100644
--- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/InternalHttpAsyncClient.java
+++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/InternalHttpAsyncClient.java
@@ -95,8 +95,17 @@ public final class InternalHttpAsyncClient extends InternalAbstractHttpAsyncClie
     }
 
     @Override
-    AsyncExecRuntime createAsyncExecRuntime(final HandlerFactory<AsyncPushConsumer> pushHandlerFactory) {
-        return new InternalHttpAsyncExecRuntime(LOG, manager, getConnectionInitiator(), pushHandlerFactory, versionPolicy);
+    AsyncExecRuntime createAsyncExecRuntime(final HandlerFactory<AsyncPushConsumer> pushHandlerFactory,
+                                            final HttpRoute route) {
+        // Automatically set protocol policy to force HTTP/1.1
+        // when executing requests via proxy tunnel
+        final HttpVersionPolicy actualVersionPolicy;
+        if (route.isTunnelled() && versionPolicy == HttpVersionPolicy.NEGOTIATE) {
+            actualVersionPolicy = HttpVersionPolicy.FORCE_HTTP_1;
+        } else {
+            actualVersionPolicy = versionPolicy;
+        }
+        return new InternalHttpAsyncExecRuntime(LOG, manager, getConnectionInitiator(), pushHandlerFactory, actualVersionPolicy);
     }
 
     @Override