ClientTlsStrategyBuilder: Set default tlsDetailsFactory

This commit is contained in:
Ryan Schmitt 2019-09-26 15:25:20 -07:00
parent a1adf79100
commit 35949e40a9
1 changed files with 17 additions and 1 deletions

View File

@ -30,6 +30,7 @@ package org.apache.hc.client5.http.ssl;
import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLEngine;
import javax.net.ssl.SSLSession;
import org.apache.hc.core5.function.Factory;
import org.apache.hc.core5.http.nio.ssl.TlsStrategy;
@ -37,6 +38,7 @@ import org.apache.hc.core5.http.ssl.TLS;
import org.apache.hc.core5.reactor.ssl.SSLBufferMode;
import org.apache.hc.core5.reactor.ssl.TlsDetails;
import org.apache.hc.core5.ssl.SSLContexts;
import org.apache.hc.core5.util.ReflectionUtils;
/**
* Builder for client {@link TlsStrategy} instances.
@ -165,13 +167,27 @@ public class ClientTlsStrategyBuilder {
} else {
ciphersCopy = systemProperties ? HttpsSupport.getSystemCipherSuits() : null;
}
final Factory<SSLEngine, TlsDetails> tlsDetailsFactoryCopy;
if (tlsDetailsFactory != null) {
tlsDetailsFactoryCopy = tlsDetailsFactory;
} else {
tlsDetailsFactoryCopy = new Factory<SSLEngine, TlsDetails>() {
@Override
public TlsDetails create(final SSLEngine sslEngine) {
final SSLSession sslSession = sslEngine.getSession();
final String applicationProtocol = ReflectionUtils.callGetter(sslEngine,
"ApplicationProtocol", String.class);
return new TlsDetails(sslSession, applicationProtocol);
}
};
}
return new DefaultClientTlsStrategy(
sslContextCopy,
tlsVersionsCopy,
ciphersCopy,
sslBufferMode != null ? sslBufferMode : SSLBufferMode.STATIC,
hostnameVerifier != null ? hostnameVerifier : HttpsSupport.getDefaultHostnameVerifier(),
tlsDetailsFactory);
tlsDetailsFactoryCopy);
}
}