Class SingleHostHttpClientBuilder
java.lang.Object
com.github.nhenneaux.resilienthttpclient.singlehostclient.SingleHostHttpClientBuilder
Create an
HttpClient to target a single host.
It validates the certificate to authenticate the server in TLS communication with this single name.
It can be used to target a single host using its IP address(es) instead of its hostname while keeping a high protection against Man-in-the-middle attack.
-Djdk.internal.httpclient.disableHostnameVerification is needed to use a custom TLS name matching based on the requested host instead of the one from the URL.
-Djdk.httpclient.allowRestrictedHeaders=Host is needed to customize the HTTP Host header.
-
Method Summary
Modifier and TypeMethodDescriptionbuild()static SingleHostHttpClientBuilderbuilder(String hostname, InetAddress hostAddress, HttpClient.Builder builder) Build a single hostname client builder.Build a client with HTTP header host overridden in Java 13+static HttpClientnewHttpClient(String hostname, InetAddress hostAddress) Build a single hostname client with default configuration.withSni()withTlsNameMatching(KeyStore trustStore) withTlsNameMatching(KeyStore trustStore, KeyStore keystore, char[] password) withTlsNameMatching(KeyStore trustStore, KeyStore keystore, char[] password, SSLContext initialSslContext) withTlsNameMatching(SSLContext initialSslContext)
-
Method Details
-
newHttpClient
Build a single hostname client with default configuration. It uses TLS matching based on the given hostname. It also provides the given hostname in SNI extension. The returned java.net.http.HttpClient is wrapped to force the HTTP headerHostwith the given hostname. -
builder
public static SingleHostHttpClientBuilder builder(String hostname, InetAddress hostAddress, HttpClient.Builder builder) Build a single hostname client builder. It could override the following elements of the builder.java.net.http.HttpClient.Builder#sslContext(javax.net.ssl.SSLContext)with a custom SSLContext using the given truststore disabling default name validation and using the given hostnamejava.net.http.HttpClient.Builder#sslParameters(javax.net.ssl.SSLParameters)to force the SNI server name expected
-
withSni
-
withTlsNameMatching
-
withTlsNameMatching
-
withTlsNameMatching
public SingleHostHttpClientBuilder withTlsNameMatching(KeyStore trustStore, KeyStore keystore, char[] password) -
buildWithHostHeader
Build a client with HTTP header host overridden in Java 13+ -
build
-
withTlsNameMatching
-
withTlsNameMatching
public SingleHostHttpClientBuilder withTlsNameMatching(KeyStore trustStore, KeyStore keystore, char[] password, SSLContext initialSslContext)
-