HTTPCLIENT-2120: force HTTP/1.1 protocol policy when creating a tunnel via HTTP/1.1 proxy

This commit is contained in:
Oleg Kalnichevski 2021-09-21 21:39:51 +02:00
parent 9496bb8475
commit 17ebfc529e
3 changed files with 15 additions and 6 deletions

View File

@ -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) {

View File

@ -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);
}
}

View File

@ -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<ManagedAsyncClientConnection> connectFuture = connectionOperator.connect(
connectionInitiator, host, localAddress, connectTimeout, attachment, new FutureCallback<ManagedAsyncClientConnection>() {
connectionInitiator,
host,
localAddress,
connectTimeout,
route.isTunnelled() ? HttpVersionPolicy.FORCE_HTTP_1 : attachment,
new FutureCallback<ManagedAsyncClientConnection>() {
@Override
public void completed(final ManagedAsyncClientConnection connection) {