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 Details

    • DEFAULT_TLS_CONFIG_MODE

      public static final com.helger.http.tls.ITLSConfigurationMode DEFAULT_TLS_CONFIG_MODE
      Default 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

      public static final Duration 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

      public HttpClientSettings(@Nonnull IHttpClientSettings aSource)
      "Copy" constructor.
      Parameters:
      aSource - The source settings to copy from. May not be null.
  • Method Details

    • setAllFrom

      @Nonnull public final HttpClientSettings setAllFrom(@Nonnull IHttpClientSettings aSource)
      Apply all settings from the provided HTTP client settings
      Parameters:
      aSource - The source settings to copy from. May not be null.
      Returns:
      this for chaining.
    • isUseDNSClientCache

      public final boolean isUseDNSClientCache()
      Specified by:
      isUseDNSClientCache in interface IHttpClientSettings
      Returns:
      true if DNS client caching is enabled (default), false if it is disabled.
    • setUseDNSClientCache

      @Nonnull public final HttpClientSettings setUseDNSClientCache(boolean bUseDNSClientCache)
      Enable or disable DNS client caching. By default caching is enabled.
      Parameters:
      bUseDNSClientCache - true to use DNS caching, false to disable it.
      Returns:
      this for chaining
    • getSSLContext

      @Nullable public final SSLContext getSSLContext()
      Create a custom SSLContext to use for the SSL Socket factory.
      Specified by:
      getSSLContext in interface IHttpClientSettings
      Returns:
      null if no custom context is present.
    • setSSLContext

      @Nonnull public final HttpClientSettings setSSLContext(@Nullable SSLContext aSSLContext)
      Set the SSL Context to be used. By default no SSL context is present.
      Parameters:
      aSSLContext - The SSL context to be used. May be null.
      Returns:
      this for chaining
    • setSSLContextTrustAll

      @Nonnull public final HttpClientSettings setSSLContextTrustAll() throws GeneralSecurityException
      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

      @Nullable public final HostnameVerifier getHostnameVerifier()
      Specified by:
      getHostnameVerifier in interface IHttpClientSettings
      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 be null.
      Returns:
      this for chaining
    • setHostnameVerifierVerifyAll

      @Nonnull public final HttpClientSettings 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:
      getTLSConfigurationMode in interface IHttpClientSettings
      Returns:
      The TLS configuration mode to be used. null means 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. null means use system default.
      Returns:
      this for chaining
    • getGeneralProxy

      @Nonnull public final HttpProxySettings getGeneralProxy()
      Specified by:
      getGeneralProxy in interface IHttpClientSettings
      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

      @Nonnull public final HttpProxySettings getHttpProxy()
      Specified by:
      getHttpProxy in interface IHttpClientSettings
      Returns:
      The HTTP proxy settings to be used exclusively for the "http" protocol. Never null.
      See Also:
    • getHttpsProxy

      @Nonnull public final HttpProxySettings getHttpsProxy()
      Specified by:
      getHttpsProxy in interface IHttpClientSettings
      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:
      getRetryCount in interface IHttpClientSettings
      Returns:
      The number of retries. Defaults to DEFAULT_RETRY_COUNT.
    • setRetryCount

      @Nonnull public final HttpClientSettings setRetryCount(@Nonnegative int nRetries)
      Set the number of internal retries.
      Parameters:
      nRetries - Retries to use. Must be ≥ 0.
      Returns:
      this for chaining
    • getRetryInterval

      @Nonnull public final Duration getRetryInterval()
      Specified by:
      getRetryInterval in interface IHttpClientSettings
      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

      @Nonnull public final HttpClientSettings setRetryInterval(@Nonnull Duration aRetryInterval)
      Set the retry interval to use.
      Parameters:
      aRetryInterval - Retry interval to use. Must not be null.
      Returns:
      this for chaining
    • isRetryAlways

      public final boolean isRetryAlways()
      Specified by:
      isRetryAlways in interface IHttpClientSettings
      Returns:
      true if retries should also be performed for non-idempotent requests.
    • setRetryAlways

      @Nonnull public final HttpClientSettings setRetryAlways(boolean bRetryAlways)
      Enable or disable to retry always. By default non-idempotent requests are not retried.
      Parameters:
      bRetryAlways - true to retry always
      Returns:
      this for chaining
      Since:
      9.7.1
    • getConnectionRequestTimeout

      @Nonnull public final org.apache.hc.core5.util.Timeout getConnectionRequestTimeout()
      Specified by:
      getConnectionRequestTimeout in interface IHttpClientSettings
      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 be null.
      Returns:
      this for chaining.
    • getConnectTimeout

      @Nonnull public final org.apache.hc.core5.util.Timeout getConnectTimeout()
      Specified by:
      getConnectTimeout in interface IHttpClientSettings
      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 be null.
      Returns:
      this for chaining.
    • getResponseTimeout

      @Nonnull public final org.apache.hc.core5.util.Timeout getResponseTimeout()
      Specified by:
      getResponseTimeout in interface IHttpClientSettings
      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 be null.
      Returns:
      this for chaining.
    • getUserAgent

      @Nullable public final String getUserAgent()
      Specified by:
      getUserAgent in interface IHttpClientSettings
      Returns:
      The user agent header to be send. May be null.
    • setUserAgent

      @Nonnull public final HttpClientSettings setUserAgent(@Nullable String sUserAgent)
      Set the optional user agent to be used. This is "just" a special HTTP header.
      Parameters:
      sUserAgent - The user agent to be used. May be null.
      Returns:
      this for chaining
      Since:
      9.1.9
    • isFollowRedirects

      public final boolean isFollowRedirects()
      Specified by:
      isFollowRedirects in interface IHttpClientSettings
      Returns:
      true if HTTP redirects (status codes 3xx) should be followed, false if not.
    • setFollowRedirects

      @Nonnull public final HttpClientSettings setFollowRedirects(boolean bFollowRedirects)
      Enable or disable if HTTP redirects (HTTP status code 3xx) should be followed or not.
      Parameters:
      bFollowRedirects - true to follow redirects, false if not.
      Returns:
      this for chaining
    • isUseKeepAlive

      public final boolean isUseKeepAlive()
      Specified by:
      isUseKeepAlive in interface IHttpClientSettings
      Returns:
      true if the HTTP Connection "Keep-Alive" should be used, false if not.
    • setUseKeepAlive

      @Nonnull public final HttpClientSettings setUseKeepAlive(boolean bUseKeepAlive)
      Enable or disable if use of the HTTP Connection "Keep-alive".
      Parameters:
      bUseKeepAlive - true to use keep-alive, false if not.
      Returns:
      this for chaining
    • isProtocolUpgradeEnabled

      public final boolean isProtocolUpgradeEnabled()
      Specified by:
      isProtocolUpgradeEnabled in interface IHttpClientSettings
      Returns:
      true if 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

      @Nonnull public final HttpClientSettings setProtocolUpgradeEnabled(boolean bProtocolUpgradeEnabled)
      Enable or disable if use of the HTTP Connection "Keep-alive".
      Parameters:
      bProtocolUpgradeEnabled - true to enable protocol upgrade, false to disable it.
      Returns:
      this for chaining
    • getClone

      @Nonnull @ReturnsMutableCopy public HttpClientSettings getClone()
      Specified by:
      getClone in interface com.helger.base.clone.ICloneable<HttpClientSettings>
    • toString

      public String toString()
      Overrides:
      toString in class Object