Refactored checks for secure schemes.
This commit is contained in:
parent
6b0e1d48c5
commit
915a905df4
|
@ -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<ContentDecoder.Factory>
|
||||
{
|
||||
private final Set<ContentDecoder.Factory> set = new HashSet<>();
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue