Package com.helger.httpclient
Class HttpClientSettings
java.lang.Object
com.helger.httpclient.HttpClientSettings
- All Implemented Interfaces:
com.helger.base.clone.ICloneable<HttpClientSettings>,IHttpClientSettings
@NotThreadSafe
public class HttpClientSettings
extends Object
implements IHttpClientSettings, com.helger.base.clone.ICloneable<HttpClientSettings>
All the easily configurable settings for an
HttpClientFactory- Since:
- 9.1.8
- Author:
- Philip Helger
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final org.apache.hc.core5.util.Timeoutstatic final org.apache.hc.core5.util.Timeoutstatic final booleanstatic final booleanstatic final org.apache.hc.core5.util.Timeoutstatic final booleanstatic final intstatic final Durationstatic final com.helger.http.tls.ITLSConfigurationModeDefault configuration modes uses TLS 1.3, TLS 1.2, 1.1 or 1.0 and no specific cipher suitesstatic final booleanstatic final booleanstatic final boolean -
Constructor Summary
ConstructorsConstructorDescriptionDefault constructor.HttpClientSettings(IHttpClientSettings aSource) "Copy" constructor. -
Method Summary
Modifier and TypeMethodDescriptiongetClone()final org.apache.hc.core5.util.Timeoutfinal org.apache.hc.core5.util.Timeoutfinal HttpProxySettingsfinal HostnameVerifierfinal HttpProxySettingsfinal HttpProxySettingsfinal org.apache.hc.core5.util.Timeoutfinal intfinal Durationfinal org.apache.hc.core5.util.TimeValuefinal SSLContextCreate a custom SSLContext to use for the SSL Socket factory.final com.helger.http.tls.ITLSConfigurationModefinal Stringfinal booleanfinal booleanfinal booleanfinal booleanfinal booleanfinal HttpClientSettingssetAllFrom(IHttpClientSettings aSource) Apply all settings from the provided HTTP client settingsfinal HttpClientSettingssetConnectionRequestTimeout(org.apache.hc.core5.util.Timeout aConnectionRequestTimeout) Set the connection request timeout to use.final HttpClientSettingssetConnectTimeout(org.apache.hc.core5.util.Timeout aConnectTimeout) Set the connect timeout to use.final HttpClientSettingssetFollowRedirects(boolean bFollowRedirects) Enable or disable if HTTP redirects (HTTP status code 3xx) should be followed or not.final HttpClientSettingssetHostnameVerifier(HostnameVerifier aHostnameVerifier) Set the hostname verifier to be used.final HttpClientSettingsAttention: INSECURE METHOD!final HttpClientSettingssetProtocolUpgradeEnabled(boolean bProtocolUpgradeEnabled) Enable or disable if use of the HTTP Connection "Keep-alive".final HttpClientSettingssetResponseTimeout(org.apache.hc.core5.util.Timeout aResponseTimeout) Set the read/socket/request timeout to use.final HttpClientSettingssetRetryAlways(boolean bRetryAlways) Enable or disable to retry always.final HttpClientSettingssetRetryCount(int nRetries) Set the number of internal retries.final HttpClientSettingssetRetryInterval(Duration aRetryInterval) Set the retry interval to use.final HttpClientSettingssetSSLContext(SSLContext aSSLContext) Set the SSL Context to be used.final HttpClientSettingsAttention: INSECURE METHOD!final HttpClientSettingssetTLSConfigurationMode(com.helger.http.tls.ITLSConfigurationMode aTLSConfigurationMode) Set the TLS configuration mode to use.final HttpClientSettingssetUseDNSClientCache(boolean bUseDNSClientCache) Enable or disable DNS client caching.final HttpClientSettingssetUseKeepAlive(boolean bUseKeepAlive) Enable or disable if use of the HTTP Connection "Keep-alive".final HttpClientSettingssetUserAgent(String sUserAgent) Set the optional user agent to be used.toString()Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface com.helger.httpclient.IHttpClientSettings
hasRetries, hasUserAgent
-
Field Details
-
DEFAULT_TLS_CONFIG_MODE
public static final com.helger.http.tls.ITLSConfigurationMode DEFAULT_TLS_CONFIG_MODEDefault configuration modes uses TLS 1.3, TLS 1.2, 1.1 or 1.0 and no specific cipher suites -
DEFAULT_USE_SYSTEM_PROPERTIES
public static final boolean DEFAULT_USE_SYSTEM_PROPERTIES- See Also:
-
DEFAULT_USE_DNS_CACHE
public static final boolean DEFAULT_USE_DNS_CACHE- See Also:
-
DEFAULT_RETRY_COUNT
public static final int DEFAULT_RETRY_COUNT- See Also:
-
DEFAULT_RETRY_INTERVAL
-
DEFAULT_RETRY_ALWAYS
public static final boolean DEFAULT_RETRY_ALWAYS- See Also:
-
DEFAULT_CONNECTION_REQUEST_TIMEOUT
public static final org.apache.hc.core5.util.Timeout DEFAULT_CONNECTION_REQUEST_TIMEOUT -
DEFAULT_CONNECT_TIMEOUT
public static final org.apache.hc.core5.util.Timeout DEFAULT_CONNECT_TIMEOUT -
DEFAULT_RESPONSE_TIMEOUT
public static final org.apache.hc.core5.util.Timeout DEFAULT_RESPONSE_TIMEOUT -
DEFAULT_FOLLOW_REDIRECTS
public static final boolean DEFAULT_FOLLOW_REDIRECTS- See Also:
-
DEFAULT_USE_KEEP_ALIVE
public static final boolean DEFAULT_USE_KEEP_ALIVE- See Also:
-
DEFAULT_PROTOCOL_UPGRADE_ENABLED
public static final boolean DEFAULT_PROTOCOL_UPGRADE_ENABLED- See Also:
-
-
Constructor Details
-
HttpClientSettings
public HttpClientSettings()Default constructor. -
HttpClientSettings
"Copy" constructor.- Parameters:
aSource- The source settings to copy from. May not benull.
-
-
Method Details
-
setAllFrom
Apply all settings from the provided HTTP client settings- Parameters:
aSource- The source settings to copy from. May not benull.- Returns:
- this for chaining.
-
isUseDNSClientCache
public final boolean isUseDNSClientCache()- Specified by:
isUseDNSClientCachein interfaceIHttpClientSettings- Returns:
trueif DNS client caching is enabled (default),falseif it is disabled.
-
setUseDNSClientCache
Enable or disable DNS client caching. By default caching is enabled.- Parameters:
bUseDNSClientCache-trueto use DNS caching,falseto disable it.- Returns:
- this for chaining
-
getSSLContext
Create a custom SSLContext to use for the SSL Socket factory.- Specified by:
getSSLContextin interfaceIHttpClientSettings- Returns:
nullif no custom context is present.
-
setSSLContext
Set the SSL Context to be used. By default no SSL context is present.- Parameters:
aSSLContext- The SSL context to be used. May benull.- Returns:
- this for chaining
-
setSSLContextTrustAll
Attention: INSECURE METHOD!
Set the a special TLS/SSL Context that does not expect any specific server certificate. To be totally loose, you should also set a hostname verifier that accepts all host names.- Returns:
- this for chaining
- Throws:
GeneralSecurityException- In case TLS initialization fails
-
getHostnameVerifier
- Specified by:
getHostnameVerifierin interfaceIHttpClientSettings- Returns:
- The current hostname verifier to be used. Default to
null.
-
setHostnameVerifier
@Nonnull public final HttpClientSettings setHostnameVerifier(@Nullable HostnameVerifier aHostnameVerifier) Set the hostname verifier to be used.- Parameters:
aHostnameVerifier- Verifier to be used. May benull.- Returns:
- this for chaining
-
setHostnameVerifierVerifyAll
Attention: INSECURE METHOD!
Set a hostname verifier that trusts all host names.- Returns:
- this for chaining
-
getTLSConfigurationMode
@Nullable public final com.helger.http.tls.ITLSConfigurationMode getTLSConfigurationMode()- Specified by:
getTLSConfigurationModein interfaceIHttpClientSettings- Returns:
- The TLS configuration mode to be used.
nullmeans to use the default settings without specific cipher suites.
-
setTLSConfigurationMode
@Nonnull public final HttpClientSettings setTLSConfigurationMode(@Nullable com.helger.http.tls.ITLSConfigurationMode aTLSConfigurationMode) Set the TLS configuration mode to use.- Parameters:
aTLSConfigurationMode- The configuration mode to use.nullmeans use system default.- Returns:
- this for chaining
-
getGeneralProxy
- Specified by:
getGeneralProxyin interfaceIHttpClientSettings- Returns:
- The general HTTP proxy settings to be used. These settings apply to any protocol,
except they are overridden in the more specific "http" and "https" proxy settings.
Never
null. - See Also:
-
getHttpProxy
- Specified by:
getHttpProxyin interfaceIHttpClientSettings- Returns:
- The HTTP proxy settings to be used exclusively for the "http" protocol. Never
null. - See Also:
-
getHttpsProxy
- Specified by:
getHttpsProxyin interfaceIHttpClientSettings- Returns:
- The HTTP proxy settings to be used exclusively for the "https" protocol. Never
null. - See Also:
-
getRetryCount
@Nonnegative public final int getRetryCount()- Specified by:
getRetryCountin interfaceIHttpClientSettings- Returns:
- The number of retries. Defaults to
DEFAULT_RETRY_COUNT.
-
setRetryCount
Set the number of internal retries.- Parameters:
nRetries- Retries to use. Must be ≥ 0.- Returns:
- this for chaining
-
getRetryInterval
- Specified by:
getRetryIntervalin interfaceIHttpClientSettings- Returns:
- The retry interval (the duration after which a retry is performed). Never
null.
-
getRetryIntervalAsTimeValue
@Nonnull public final org.apache.hc.core5.util.TimeValue getRetryIntervalAsTimeValue() -
setRetryInterval
Set the retry interval to use.- Parameters:
aRetryInterval- Retry interval to use. Must not benull.- Returns:
- this for chaining
-
isRetryAlways
public final boolean isRetryAlways()- Specified by:
isRetryAlwaysin interfaceIHttpClientSettings- Returns:
trueif retries should also be performed for non-idempotent requests.
-
setRetryAlways
Enable or disable to retry always. By default non-idempotent requests are not retried.- Parameters:
bRetryAlways-trueto retry always- Returns:
- this for chaining
- Since:
- 9.7.1
-
getConnectionRequestTimeout
@Nonnull public final org.apache.hc.core5.util.Timeout getConnectionRequestTimeout()- Specified by:
getConnectionRequestTimeoutin interfaceIHttpClientSettings- Returns:
- The connection request timeout in milliseconds. A value of 0 means "indefinite". Never
null.
-
setConnectionRequestTimeout
@Nonnull public final HttpClientSettings setConnectionRequestTimeout(@Nonnull org.apache.hc.core5.util.Timeout aConnectionRequestTimeout) Set the connection request timeout to use.- Parameters:
aConnectionRequestTimeout- Timeout to be used. May not benull.- Returns:
- this for chaining.
-
getConnectTimeout
@Nonnull public final org.apache.hc.core5.util.Timeout getConnectTimeout()- Specified by:
getConnectTimeoutin interfaceIHttpClientSettings- Returns:
- The connect timeout. Never
null.
-
setConnectTimeout
@Nonnull public final HttpClientSettings setConnectTimeout(@Nonnull org.apache.hc.core5.util.Timeout aConnectTimeout) Set the connect timeout to use.- Parameters:
aConnectTimeout- Timeout to be used. May not benull.- Returns:
- this for chaining.
-
getResponseTimeout
@Nonnull public final org.apache.hc.core5.util.Timeout getResponseTimeout()- Specified by:
getResponseTimeoutin interfaceIHttpClientSettings- Returns:
- The response/read/request/socket timeout. Never
null.
-
setResponseTimeout
@Nonnull public final HttpClientSettings setResponseTimeout(@Nonnull org.apache.hc.core5.util.Timeout aResponseTimeout) Set the read/socket/request timeout to use.- Parameters:
aResponseTimeout- Timeout to be used. May not benull.- Returns:
- this for chaining.
-
getUserAgent
- Specified by:
getUserAgentin interfaceIHttpClientSettings- Returns:
- The user agent header to be send. May be
null.
-
setUserAgent
Set the optional user agent to be used. This is "just" a special HTTP header.- Parameters:
sUserAgent- The user agent to be used. May benull.- Returns:
- this for chaining
- Since:
- 9.1.9
-
isFollowRedirects
public final boolean isFollowRedirects()- Specified by:
isFollowRedirectsin interfaceIHttpClientSettings- Returns:
trueif HTTP redirects (status codes 3xx) should be followed,falseif not.
-
setFollowRedirects
Enable or disable if HTTP redirects (HTTP status code 3xx) should be followed or not.- Parameters:
bFollowRedirects-trueto follow redirects,falseif not.- Returns:
- this for chaining
-
isUseKeepAlive
public final boolean isUseKeepAlive()- Specified by:
isUseKeepAlivein interfaceIHttpClientSettings- Returns:
trueif the HTTP Connection "Keep-Alive" should be used,falseif not.
-
setUseKeepAlive
Enable or disable if use of the HTTP Connection "Keep-alive".- Parameters:
bUseKeepAlive-trueto use keep-alive,falseif not.- Returns:
- this for chaining
-
isProtocolUpgradeEnabled
public final boolean isProtocolUpgradeEnabled()- Specified by:
isProtocolUpgradeEnabledin interfaceIHttpClientSettings- Returns:
trueif a protocol upgrade e.g. from http to https should be done automatically or not. Since Apache HttpClient 5.4 this became the default.
-
setProtocolUpgradeEnabled
Enable or disable if use of the HTTP Connection "Keep-alive".- Parameters:
bProtocolUpgradeEnabled-trueto enable protocol upgrade,falseto disable it.- Returns:
- this for chaining
-
getClone
- Specified by:
getClonein interfacecom.helger.base.clone.ICloneable<HttpClientSettings>
-
toString
-