diff --git a/jetty-client/src/main/java/org/eclipse/jetty/client/HttpClient.java b/jetty-client/src/main/java/org/eclipse/jetty/client/HttpClient.java index 0720751663d..cbf15b6fffd 100644 --- a/jetty-client/src/main/java/org/eclipse/jetty/client/HttpClient.java +++ b/jetty-client/src/main/java/org/eclipse/jetty/client/HttpClient.java @@ -1039,7 +1039,7 @@ public class HttpClient extends ContainerLifeCycle { if (port > 0) return port; - else if (HttpScheme.HTTPS.is(scheme) || HttpScheme.WSS.is(scheme)) + else if (isSchemeSecure(scheme)) return 443; else return 80; @@ -1047,12 +1047,17 @@ public class HttpClient extends ContainerLifeCycle public boolean isDefaultPort(String scheme, int port) { - if (HttpScheme.HTTPS.is(scheme) || HttpScheme.WSS.is(scheme)) + if (isSchemeSecure(scheme)) return port == 443; - else + else return port == 80; } + public boolean isSchemeSecure(String scheme) + { + return HttpScheme.HTTPS.is(scheme) || HttpScheme.WSS.is(scheme); + } + private class ContentDecoderFactorySet implements Set { private final Set set = new HashSet<>(); diff --git a/jetty-client/src/main/java/org/eclipse/jetty/client/HttpDestination.java b/jetty-client/src/main/java/org/eclipse/jetty/client/HttpDestination.java index ff24d7b3b13..e59be2f026c 100644 --- a/jetty-client/src/main/java/org/eclipse/jetty/client/HttpDestination.java +++ b/jetty-client/src/main/java/org/eclipse/jetty/client/HttpDestination.java @@ -31,7 +31,6 @@ import org.eclipse.jetty.client.api.Destination; import org.eclipse.jetty.client.api.Response; import org.eclipse.jetty.http.HttpField; import org.eclipse.jetty.http.HttpHeader; -import org.eclipse.jetty.http.HttpScheme; import org.eclipse.jetty.io.ClientConnectionFactory; import org.eclipse.jetty.io.ssl.SslClientConnectionFactory; import org.eclipse.jetty.util.BlockingArrayQueue; @@ -76,7 +75,7 @@ public abstract class HttpDestination extends ContainerLifeCycle implements Dest } else { - if (HttpScheme.HTTPS.is(getScheme()) || HttpScheme.WSS.is(getScheme())) + if (isSecure()) connectionFactory = newSslClientConnectionFactory(connectionFactory); } this.connectionFactory = connectionFactory; @@ -97,6 +96,11 @@ public abstract class HttpDestination extends ContainerLifeCycle implements Dest return new SslClientConnectionFactory(client.getSslContextFactory(), client.getByteBufferPool(), client.getExecutor(), connectionFactory); } + public boolean isSecure() + { + return client.isSchemeSecure(getScheme()); + } + public HttpClient getHttpClient() { return client; diff --git a/jetty-client/src/main/java/org/eclipse/jetty/client/HttpProxy.java b/jetty-client/src/main/java/org/eclipse/jetty/client/HttpProxy.java index 7199f17eb74..2a92a5d42ab 100644 --- a/jetty-client/src/main/java/org/eclipse/jetty/client/HttpProxy.java +++ b/jetty-client/src/main/java/org/eclipse/jetty/client/HttpProxy.java @@ -107,7 +107,7 @@ public class HttpProxy extends ProxyConfiguration.Proxy public void succeeded(Connection connection) { HttpDestination destination = (HttpDestination)context.get(HttpClientTransport.HTTP_DESTINATION_CONTEXT_KEY); - if (HttpScheme.HTTPS.is(destination.getScheme()) || HttpScheme.WSS.is(destination.getScheme())) + if (destination.isSecure()) { SslContextFactory sslContextFactory = destination.getHttpClient().getSslContextFactory(); if (sslContextFactory != null) diff --git a/jetty-client/src/main/java/org/eclipse/jetty/client/Socks4Proxy.java b/jetty-client/src/main/java/org/eclipse/jetty/client/Socks4Proxy.java index f73932c111e..246681e646a 100644 --- a/jetty-client/src/main/java/org/eclipse/jetty/client/Socks4Proxy.java +++ b/jetty-client/src/main/java/org/eclipse/jetty/client/Socks4Proxy.java @@ -27,7 +27,6 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; import org.eclipse.jetty.client.api.Connection; -import org.eclipse.jetty.http.HttpScheme; import org.eclipse.jetty.io.AbstractConnection; import org.eclipse.jetty.io.ClientConnectionFactory; import org.eclipse.jetty.io.EndPoint; @@ -196,7 +195,7 @@ public class Socks4Proxy extends ProxyConfiguration.Proxy HttpDestination destination = (HttpDestination)context.get(HttpClientTransport.HTTP_DESTINATION_CONTEXT_KEY); HttpClient client = destination.getHttpClient(); ClientConnectionFactory connectionFactory = this.connectionFactory; - if (HttpScheme.HTTPS.is(destination.getScheme()) || HttpScheme.WSS.is(destination.getScheme())) + if (destination.isSecure()) connectionFactory = new SslClientConnectionFactory(client.getSslContextFactory(), client.getByteBufferPool(), client.getExecutor(), connectionFactory); org.eclipse.jetty.io.Connection newConnection = connectionFactory.newConnection(getEndPoint(), context); getEndPoint().upgrade(newConnection);