From bdc7f3b93e36a1601240dc65dcde526e76dd4ff1 Mon Sep 17 00:00:00 2001 From: Oleg Kalnichevski Date: Thu, 9 Sep 2021 14:00:20 +0200 Subject: [PATCH] Upgraded HttpCore to version 5.2-alpha1 --- .../impl/async/AsyncHttpRequestRetryExec.java | 4 +-- .../DefaultAsyncClientConnectionOperator.java | 7 ++--- .../http/ssl/AbstractClientTlsStrategy.java | 26 +++++++++++++++---- .../http/ssl/ConscryptClientTlsStrategy.java | 3 +-- .../http/ssl/DefaultClientTlsStrategy.java | 3 +-- pom.xml | 3 ++- 6 files changed, 29 insertions(+), 17 deletions(-) diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/AsyncHttpRequestRetryExec.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/AsyncHttpRequestRetryExec.java index 186a3314f..b12a8159e 100644 --- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/AsyncHttpRequestRetryExec.java +++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/AsyncHttpRequestRetryExec.java @@ -43,7 +43,7 @@ import org.apache.hc.core5.http.HttpRequest; import org.apache.hc.core5.http.HttpResponse; import org.apache.hc.core5.http.nio.AsyncDataConsumer; import org.apache.hc.core5.http.nio.AsyncEntityProducer; -import org.apache.hc.core5.http.nio.entity.NoopEntityConsumer; +import org.apache.hc.core5.http.nio.entity.DiscardingEntityConsumer; import org.apache.hc.core5.http.support.BasicRequestBuilder; import org.apache.hc.core5.util.Args; import org.apache.hc.core5.util.TimeValue; @@ -113,7 +113,7 @@ public final class AsyncHttpRequestRetryExec implements AsyncExecChainHandler { if (LOG.isDebugEnabled()) { LOG.debug("{} retrying request in {}", exchangeId, state.delay); } - return new NoopEntityConsumer(); + return new DiscardingEntityConsumer<>(); } else { return asyncExecCallback.handleResponse(response, entityDetails); } diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/nio/DefaultAsyncClientConnectionOperator.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/nio/DefaultAsyncClientConnectionOperator.java index 6d89f2a79..65c918670 100644 --- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/nio/DefaultAsyncClientConnectionOperator.java +++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/nio/DefaultAsyncClientConnectionOperator.java @@ -94,10 +94,8 @@ final class DefaultAsyncClientConnectionOperator implements AsyncClientConnectio tlsStrategy.upgrade( connection, host, - session.getLocalAddress(), - session.getRemoteAddress(), attachment, - connectTimeout); + connectTimeout, null); } catch (final Exception ex) { future.failed(ex); return; @@ -128,9 +126,8 @@ final class DefaultAsyncClientConnectionOperator implements AsyncClientConnectio tlsStrategy.upgrade( connection, host, - connection.getLocalAddress(), - connection.getRemoteAddress(), attachment, + null, null); } diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/ssl/AbstractClientTlsStrategy.java b/httpclient5/src/main/java/org/apache/hc/client5/http/ssl/AbstractClientTlsStrategy.java index 474ab7d66..45a66f71b 100644 --- a/httpclient5/src/main/java/org/apache/hc/client5/http/ssl/AbstractClientTlsStrategy.java +++ b/httpclient5/src/main/java/org/apache/hc/client5/http/ssl/AbstractClientTlsStrategy.java @@ -40,6 +40,7 @@ import javax.net.ssl.SSLSession; import org.apache.hc.core5.annotation.Contract; import org.apache.hc.core5.annotation.ThreadingBehavior; +import org.apache.hc.core5.concurrent.FutureCallback; import org.apache.hc.core5.http.HttpHost; import org.apache.hc.core5.http.nio.ssl.TlsStrategy; import org.apache.hc.core5.http.ssl.TLS; @@ -47,6 +48,7 @@ import org.apache.hc.core5.http.ssl.TlsCiphers; import org.apache.hc.core5.http2.HttpVersionPolicy; import org.apache.hc.core5.http2.ssl.ApplicationProtocol; import org.apache.hc.core5.http2.ssl.H2TlsSupport; +import org.apache.hc.core5.net.NamedEndpoint; import org.apache.hc.core5.reactor.ssl.SSLBufferMode; import org.apache.hc.core5.reactor.ssl.TlsDetails; import org.apache.hc.core5.reactor.ssl.TransportSecurityLayer; @@ -82,6 +84,10 @@ abstract class AbstractClientTlsStrategy implements TlsStrategy { this.tlsSessionValidator = new TlsSessionValidator(LOG); } + /** + * @deprecated use {@link #upgrade(TransportSecurityLayer, NamedEndpoint, Object, Timeout, FutureCallback)} + */ + @Deprecated @Override public boolean upgrade( final TransportSecurityLayer tlsSession, @@ -90,7 +96,18 @@ abstract class AbstractClientTlsStrategy implements TlsStrategy { final SocketAddress remoteAddress, final Object attachment, final Timeout handshakeTimeout) { - tlsSession.startTls(sslContext, host, sslBufferManagement, (endpoint, sslEngine) -> { + upgrade(tlsSession, host, attachment, handshakeTimeout, null); + return true; + } + + @Override + public void upgrade( + final TransportSecurityLayer tlsSession, + final NamedEndpoint endpoint, + final Object attachment, + final Timeout handshakeTimeout, + final FutureCallback callback) { + tlsSession.startTls(sslContext, endpoint, sslBufferManagement, (e, sslEngine) -> { final HttpVersionPolicy versionPolicy = attachment instanceof HttpVersionPolicy ? (HttpVersionPolicy) attachment : HttpVersionPolicy.NEGOTIATE; @@ -119,8 +136,8 @@ abstract class AbstractClientTlsStrategy implements TlsStrategy { LOG.debug("Enabled protocols: {}", Arrays.asList(sslEngine.getEnabledProtocols())); LOG.debug("Enabled cipher suites:{}", Arrays.asList(sslEngine.getEnabledCipherSuites())); } - }, (endpoint, sslEngine) -> { - verifySession(host.getHostName(), sslEngine.getSession()); + }, (e, sslEngine) -> { + verifySession(endpoint.getHostName(), sslEngine.getSession()); final TlsDetails tlsDetails = createTlsDetails(sslEngine); final String negotiatedCipherSuite = sslEngine.getSession().getCipherSuite(); if (tlsDetails != null && ApplicationProtocol.HTTP_2.id.equals(tlsDetails.getApplicationProtocol())) { @@ -130,8 +147,7 @@ abstract class AbstractClientTlsStrategy implements TlsStrategy { } } return tlsDetails; - }, handshakeTimeout); - return true; + }, handshakeTimeout, callback); } abstract void applyParameters(SSLEngine sslEngine, SSLParameters sslParameters, String[] appProtocols); diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/ssl/ConscryptClientTlsStrategy.java b/httpclient5/src/main/java/org/apache/hc/client5/http/ssl/ConscryptClientTlsStrategy.java index 16d0e7d32..d3799d559 100644 --- a/httpclient5/src/main/java/org/apache/hc/client5/http/ssl/ConscryptClientTlsStrategy.java +++ b/httpclient5/src/main/java/org/apache/hc/client5/http/ssl/ConscryptClientTlsStrategy.java @@ -38,7 +38,6 @@ import javax.net.ssl.SSLParameters; import org.apache.hc.core5.annotation.Contract; import org.apache.hc.core5.annotation.ThreadingBehavior; import org.apache.hc.core5.http.nio.ssl.TlsStrategy; -import org.apache.hc.core5.http2.ssl.H2TlsSupport; import org.apache.hc.core5.reactor.ssl.SSLBufferMode; import org.apache.hc.core5.reactor.ssl.TlsDetails; import org.apache.hc.core5.ssl.SSLContexts; @@ -92,7 +91,7 @@ public class ConscryptClientTlsStrategy extends AbstractClientTlsStrategy { sslEngine.setSSLParameters(sslParameters); Conscrypt.setApplicationProtocols(sslEngine, appProtocols); } else { - H2TlsSupport.setApplicationProtocols(sslParameters, appProtocols); + sslParameters.setApplicationProtocols(appProtocols); sslEngine.setSSLParameters(sslParameters); } } diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/ssl/DefaultClientTlsStrategy.java b/httpclient5/src/main/java/org/apache/hc/client5/http/ssl/DefaultClientTlsStrategy.java index 9a089db33..872605dc4 100644 --- a/httpclient5/src/main/java/org/apache/hc/client5/http/ssl/DefaultClientTlsStrategy.java +++ b/httpclient5/src/main/java/org/apache/hc/client5/http/ssl/DefaultClientTlsStrategy.java @@ -36,7 +36,6 @@ import org.apache.hc.core5.annotation.Contract; import org.apache.hc.core5.annotation.ThreadingBehavior; import org.apache.hc.core5.function.Factory; import org.apache.hc.core5.http.nio.ssl.TlsStrategy; -import org.apache.hc.core5.http2.ssl.H2TlsSupport; import org.apache.hc.core5.reactor.ssl.SSLBufferMode; import org.apache.hc.core5.reactor.ssl.TlsDetails; import org.apache.hc.core5.ssl.SSLContexts; @@ -98,7 +97,7 @@ public class DefaultClientTlsStrategy extends AbstractClientTlsStrategy { @Override void applyParameters(final SSLEngine sslEngine, final SSLParameters sslParameters, final String[] appProtocols) { - H2TlsSupport.setApplicationProtocols(sslParameters, appProtocols); + sslParameters.setApplicationProtocols(appProtocols); sslEngine.setSSLParameters(sslParameters); } diff --git a/pom.xml b/pom.xml index f49b93e5a..fcec8b80b 100644 --- a/pom.xml +++ b/pom.xml @@ -62,7 +62,7 @@ 1.8 1.8 - 5.1.1 + 5.2-alpha1 2.9.1 1.15 2.2.1 @@ -75,6 +75,7 @@ 1 2.2.7 5.1 + javax.net.ssl.SSLEngine,javax.net.ssl.SSLParameters