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 763d9c3a1..c5903c5a4 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 @@ -95,6 +95,13 @@ public class HttpAsyncClientCompatibilityTest { new HttpAsyncClientCompatibilityTest( HttpVersionPolicy.NEGOTIATE, new HttpHost("https", "test-httpd", 8443), new HttpHost("localhost", 8889), + new UsernamePasswordCredentials("squid", "nopassword".toCharArray())), + new HttpAsyncClientCompatibilityTest( + HttpVersionPolicy.FORCE_HTTP_2, + new HttpHost("https", "test-httpd", 8443), new HttpHost("localhost", 8888), null), + new HttpAsyncClientCompatibilityTest( + HttpVersionPolicy.FORCE_HTTP_2, + new HttpHost("https", "test-httpd", 8443), new HttpHost("localhost", 8889), new UsernamePasswordCredentials("squid", "nopassword".toCharArray())) }; for (final HttpAsyncClientCompatibilityTest test: tests) { 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 c2b7c5c69..2dc8a4218 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 @@ -101,11 +101,7 @@ public final class InternalHttpAsyncClient extends InternalAbstractHttpAsyncClie @Override HttpRoute determineRoute(final HttpHost httpHost, final HttpClientContext clientContext) throws HttpException { - final HttpRoute route = routePlanner.determineRoute(httpHost, clientContext); - if (route.isTunnelled() && versionPolicy == HttpVersionPolicy.FORCE_HTTP_2) { - throw new HttpException("HTTP/2 tunneling not supported"); - } - return route; + return routePlanner.determineRoute(httpHost, clientContext); } } diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/nio/PoolingAsyncClientConnectionManager.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/nio/PoolingAsyncClientConnectionManager.java index 3bc64abff..3617b592e 100644 --- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/nio/PoolingAsyncClientConnectionManager.java +++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/nio/PoolingAsyncClientConnectionManager.java @@ -67,6 +67,7 @@ import org.apache.hc.core5.http.nio.HandlerFactory; import org.apache.hc.core5.http.nio.command.RequestExecutionCommand; import org.apache.hc.core5.http.nio.ssl.TlsStrategy; import org.apache.hc.core5.http.protocol.HttpContext; +import org.apache.hc.core5.http2.HttpVersionPolicy; import org.apache.hc.core5.http2.nio.command.PingCommand; import org.apache.hc.core5.http2.nio.support.BasicPingHandler; import org.apache.hc.core5.http2.ssl.ApplicationProtocol; @@ -405,7 +406,12 @@ public class PoolingAsyncClientConnectionManager implements AsyncClientConnectio LOG.debug("{} connecting endpoint to {} ({})", ConnPoolSupport.getId(endpoint), host, connectTimeout); } final Future connectFuture = connectionOperator.connect( - connectionInitiator, host, localAddress, connectTimeout, attachment, new FutureCallback() { + connectionInitiator, + host, + localAddress, + connectTimeout, + route.isTunnelled() ? HttpVersionPolicy.FORCE_HTTP_1 : attachment, + new FutureCallback() { @Override public void completed(final ManagedAsyncClientConnection connection) {