Re-use core URIScheme instead of String.

This commit is contained in:
Arturo Bernal 2021-10-17 12:56:38 +02:00 committed by Oleg Kalnichevski
parent 238401731b
commit bc7aae743a
4 changed files with 8 additions and 5 deletions

View File

@ -118,9 +118,9 @@ public Credentials getCredentials(final AuthScope authScope, final HttpContext c
// https.proxyUser/https.proxyPassword. We cannot simply use the protocol from // https.proxyUser/https.proxyPassword. We cannot simply use the protocol from
// the origin since a proxy retrieved from https.proxyHost/https.proxyPort will // the origin since a proxy retrieved from https.proxyHost/https.proxyPort will
// still use http as protocol // still use http as protocol
systemcreds = getProxyCredentials("http", authScope); systemcreds = getProxyCredentials(URIScheme.HTTP.getId(), authScope);
if (systemcreds == null) { if (systemcreds == null) {
systemcreds = getProxyCredentials("https", authScope); systemcreds = getProxyCredentials(URIScheme.HTTPS.getId(), authScope);
} }
} }
if (systemcreds != null) { if (systemcreds != null) {

View File

@ -60,6 +60,7 @@
import org.apache.hc.core5.http.HttpHost; import org.apache.hc.core5.http.HttpHost;
import org.apache.hc.core5.http.HttpVersion; import org.apache.hc.core5.http.HttpVersion;
import org.apache.hc.core5.http.ProtocolVersion; import org.apache.hc.core5.http.ProtocolVersion;
import org.apache.hc.core5.http.URIScheme;
import org.apache.hc.core5.http.config.Lookup; import org.apache.hc.core5.http.config.Lookup;
import org.apache.hc.core5.http.config.RegistryBuilder; import org.apache.hc.core5.http.config.RegistryBuilder;
import org.apache.hc.core5.http.nio.AsyncClientExchangeHandler; import org.apache.hc.core5.http.nio.AsyncClientExchangeHandler;
@ -128,7 +129,7 @@ public class PoolingAsyncClientConnectionManager implements AsyncClientConnectio
public PoolingAsyncClientConnectionManager() { public PoolingAsyncClientConnectionManager() {
this(RegistryBuilder.<TlsStrategy>create() this(RegistryBuilder.<TlsStrategy>create()
.register("https", DefaultClientTlsStrategy.getDefault()) .register(URIScheme.HTTPS.getId(), DefaultClientTlsStrategy.getDefault())
.build()); .build());
} }

View File

@ -36,6 +36,7 @@
import org.apache.hc.client5.http.ssl.DefaultClientTlsStrategy; import org.apache.hc.client5.http.ssl.DefaultClientTlsStrategy;
import org.apache.hc.core5.function.Resolver; import org.apache.hc.core5.function.Resolver;
import org.apache.hc.core5.http.HttpHost; import org.apache.hc.core5.http.HttpHost;
import org.apache.hc.core5.http.URIScheme;
import org.apache.hc.core5.http.config.RegistryBuilder; import org.apache.hc.core5.http.config.RegistryBuilder;
import org.apache.hc.core5.http.io.SocketConfig; import org.apache.hc.core5.http.io.SocketConfig;
import org.apache.hc.core5.http.nio.ssl.TlsStrategy; import org.apache.hc.core5.http.nio.ssl.TlsStrategy;
@ -247,7 +248,7 @@ public PoolingAsyncClientConnectionManager build() {
} }
final PoolingAsyncClientConnectionManager poolingmgr = new PoolingAsyncClientConnectionManager( final PoolingAsyncClientConnectionManager poolingmgr = new PoolingAsyncClientConnectionManager(
RegistryBuilder.<TlsStrategy>create() RegistryBuilder.<TlsStrategy>create()
.register("https", tlsStrategyCopy) .register(URIScheme.HTTPS.getId(), tlsStrategyCopy)
.build(), .build(),
poolConcurrencyPolicy, poolConcurrencyPolicy,
poolReusePolicy, poolReusePolicy,

View File

@ -41,6 +41,7 @@
import org.apache.hc.core5.http.HttpException; import org.apache.hc.core5.http.HttpException;
import org.apache.hc.core5.http.HttpHost; import org.apache.hc.core5.http.HttpHost;
import org.apache.hc.core5.http.ProtocolException; import org.apache.hc.core5.http.ProtocolException;
import org.apache.hc.core5.http.URIScheme;
import org.apache.hc.core5.http.protocol.HttpContext; import org.apache.hc.core5.http.protocol.HttpContext;
/** /**
@ -75,7 +76,7 @@ public final HttpRoute determineRoute(final HttpHost host, final HttpContext con
if (target.getPort() < 0) { if (target.getPort() < 0) {
throw new ProtocolException("Unroutable protocol scheme: " + target); throw new ProtocolException("Unroutable protocol scheme: " + target);
} }
final boolean secure = target.getSchemeName().equalsIgnoreCase("https"); final boolean secure = target.getSchemeName().equalsIgnoreCase(URIScheme.HTTPS.getId());
if (proxy == null) { if (proxy == null) {
return new HttpRoute(target, determineLocalAddress(target, context), secure); return new HttpRoute(target, determineLocalAddress(target, context), secure);
} }