Bug fix: HTTP protocol negotiator factories to accept null TlsStrategy
diff --git a/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/ClientHttpProtocolNegotiatorFactory.java b/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/ClientHttpProtocolNegotiatorFactory.java
index 6800702..e257ae9 100644
--- a/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/ClientHttpProtocolNegotiatorFactory.java
+++ b/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/ClientHttpProtocolNegotiatorFactory.java
@@ -33,12 +33,13 @@
import org.apache.hc.core5.http.HttpHost;
import org.apache.hc.core5.http.URIScheme;
import org.apache.hc.core5.http.impl.nio.ClientHttp1StreamDuplexerFactory;
-import org.apache.hc.core5.reactor.EndpointParameters;
import org.apache.hc.core5.http.nio.ssl.TlsStrategy;
import org.apache.hc.core5.http2.HttpVersionPolicy;
+import org.apache.hc.core5.reactor.EndpointParameters;
import org.apache.hc.core5.reactor.IOEventHandlerFactory;
import org.apache.hc.core5.reactor.ProtocolIOSession;
import org.apache.hc.core5.util.Args;
+import org.apache.hc.core5.util.Asserts;
import org.apache.hc.core5.util.Timeout;
/**
@@ -65,7 +66,7 @@
this.http1StreamHandlerFactory = Args.notNull(http1StreamHandlerFactory, "HTTP/1.1 stream handler factory");
this.http2StreamHandlerFactory = Args.notNull(http2StreamHandlerFactory, "HTTP/2 stream handler factory");
this.versionPolicy = versionPolicy != null ? versionPolicy : HttpVersionPolicy.NEGOTIATE;
- this.tlsStrategy = Args.notNull(tlsStrategy, "TLS strategy");
+ this.tlsStrategy = tlsStrategy;
this.handshakeTimeout = handshakeTimeout;
}
@@ -74,7 +75,8 @@
HttpVersionPolicy endpointPolicy = versionPolicy;
if (attachment instanceof EndpointParameters) {
final EndpointParameters params = (EndpointParameters) attachment;
- if (tlsStrategy != null && URIScheme.HTTPS.same(params.getScheme())) {
+ if (URIScheme.HTTPS.same(params.getScheme())) {
+ Asserts.notNull(tlsStrategy, "TLS strategy");
final HttpHost host = new HttpHost(params.getScheme(), params.getHostName(), params.getPort());
tlsStrategy.upgrade(
ioSession,
diff --git a/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/ServerHttpProtocolNegotiatorFactory.java b/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/ServerHttpProtocolNegotiatorFactory.java
index 35ca32f..e3f432c 100644
--- a/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/ServerHttpProtocolNegotiatorFactory.java
+++ b/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/ServerHttpProtocolNegotiatorFactory.java
@@ -31,13 +31,14 @@
import org.apache.hc.core5.annotation.Internal;
import org.apache.hc.core5.annotation.ThreadingBehavior;
import org.apache.hc.core5.http.URIScheme;
-import org.apache.hc.core5.reactor.EndpointParameters;
import org.apache.hc.core5.http.impl.nio.ServerHttp1StreamDuplexerFactory;
import org.apache.hc.core5.http.nio.ssl.TlsStrategy;
import org.apache.hc.core5.http2.HttpVersionPolicy;
+import org.apache.hc.core5.reactor.EndpointParameters;
import org.apache.hc.core5.reactor.IOEventHandlerFactory;
import org.apache.hc.core5.reactor.ProtocolIOSession;
import org.apache.hc.core5.util.Args;
+import org.apache.hc.core5.util.Asserts;
import org.apache.hc.core5.util.Timeout;
/**
@@ -64,7 +65,7 @@
this.http1StreamDuplexerFactory = Args.notNull(http1StreamDuplexerFactory, "HTTP/1.1 stream handler factory");
this.http2StreamMultiplexerFactory = Args.notNull(http2StreamMultiplexerFactory, "HTTP/2 stream handler factory");
this.versionPolicy = versionPolicy != null ? versionPolicy : HttpVersionPolicy.NEGOTIATE;
- this.tlsStrategy = Args.notNull(tlsStrategy, "TLS strategy");
+ this.tlsStrategy = tlsStrategy;
this.handshakeTimeout = handshakeTimeout;
}
@@ -73,7 +74,8 @@
HttpVersionPolicy endpointPolicy = versionPolicy;
if (attachment instanceof EndpointParameters) {
final EndpointParameters params = (EndpointParameters) attachment;
- if (tlsStrategy != null && URIScheme.HTTPS.same(params.getScheme())) {
+ if (URIScheme.HTTPS.same(params.getScheme())) {
+ Asserts.notNull(tlsStrategy, "TLS strategy");
tlsStrategy.upgrade(
ioSession,
null,