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/17 20:38:34 UTC

[httpcomponents-client] branch HTTPCLIENT-2177 updated: 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 HTTPCLIENT-2177
in repository https://gitbox.apache.org/repos/asf/httpcomponents-client.git


The following commit(s) were added to refs/heads/HTTPCLIENT-2177 by this push:
     new b490803  HTTPCLIENT-2177: automatically force HTTP/1.1 protocol policy when executing requests via a proxy tunnel
b490803 is described below

commit b49080353fbe554181b3d0d25e8521db1424ecce
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
---
 .../testing/external/HttpAsyncClientCompatibilityTest.java  |  9 ++++++++-
 .../http/impl/async/InternalAbstractHttpAsyncClient.java    |  5 +++--
 .../hc/client5/http/impl/async/InternalH2AsyncClient.java   |  3 ++-
 .../hc/client5/http/impl/async/InternalHttpAsyncClient.java | 13 +++++++++++--
 4 files changed, 24 insertions(+), 6 deletions(-)

diff --git a/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/external/HttpAsyncClientCompatibilityTest.java b/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/external/HttpAsyncClientCompatibilityTest.java
index e9eb959..27aefaa 100644
--- a/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/external/HttpAsyncClientCompatibilityTest.java
+++ b/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/external/HttpAsyncClientCompatibilityTest.java
@@ -88,7 +88,14 @@ public class HttpAsyncClientCompatibilityTest {
                         new HttpHost("http", "localhost", 8080), null, null),
                 new HttpAsyncClientCompatibilityTest(
                         HttpVersionPolicy.FORCE_HTTP_2,
-                        new HttpHost("https", "localhost", 8443), null, null)
+                        new HttpHost("https", "localhost", 8443), null, null),
+                new HttpAsyncClientCompatibilityTest(
+                        HttpVersionPolicy.NEGOTIATE,
+                        new HttpHost("https", "test-httpd", 8443), new HttpHost("localhost", 8888), null),
+                new HttpAsyncClientCompatibilityTest(
+                        HttpVersionPolicy.NEGOTIATE,
+                        new HttpHost("https", "test-httpd", 8443), new HttpHost("localhost", 8889),
+                        new UsernamePasswordCredentials("squid", "nopassword".toCharArray()))
         };
         for (final HttpAsyncClientCompatibilityTest test: tests) {
             try {
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 6dac275..1becadd 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
@@ -158,7 +158,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;
 
@@ -198,7 +199,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);
 
                     clientContext.setExchangeId(exchangeId);
                     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