Class HttpClientOptions

java.lang.Object
com.azure.core.util.ClientOptions
com.azure.core.util.HttpClientOptions

public final class HttpClientOptions extends ClientOptions
General configuration options for HttpClients.

HttpClient implementations may not support all configuration options in this class.

  • Constructor Details

    • HttpClientOptions

      public HttpClientOptions()
  • Method Details

    • setApplicationId

      public HttpClientOptions setApplicationId(String applicationId)
      Description copied from class: ClientOptions
      Sets the application ID.

      The applicationId is used to configure UserAgentPolicy for telemetry/monitoring purposes.

      See Azure Core: Telemetry policy for additional information.

      Code Samples

      Create ClientOptions with application ID 'myApplicationId'

       ClientOptions clientOptions = new ClientOptions()
           .setApplicationId("myApplicationId");
       
      Overrides:
      setApplicationId in class ClientOptions
      Parameters:
      applicationId - The application ID.
      Returns:
      The updated ClientOptions object.
    • setHeaders

      public HttpClientOptions setHeaders(Iterable<Header> headers)
      Description copied from class: ClientOptions
      Sets the Headers.

      The passed headers are applied to each request sent with the client.

      This overwrites all previously set headers.

      Code Samples

      Create ClientOptions with Header 'myCustomHeader':'myStaticValue'

       ClientOptions clientOptions = new ClientOptions()
           .setHeaders(Collections.singletonList(new Header("myCustomHeader", "myStaticValue")));
       
      Overrides:
      setHeaders in class ClientOptions
      Parameters:
      headers - The headers.
      Returns:
      The updated ClientOptions object.
    • setProxyOptions

      public HttpClientOptions setProxyOptions(ProxyOptions proxyOptions)
      Sets the proxy options that the HttpClient will use.
      Parameters:
      proxyOptions - The proxy options to use.
      Returns:
      The updated HttpClientOptions object.
    • getProxyOptions

      public ProxyOptions getProxyOptions()
      Gets the proxy options that the HttpClient will use.
      Returns:
      The proxy options to use.
    • setConfiguration

      public HttpClientOptions setConfiguration(Configuration configuration)
      Sets the configuration store that the HttpClient will use.
      Parameters:
      configuration - The configuration store to use.
      Returns:
      The updated HttpClientOptions object.
    • getConfiguration

      public Configuration getConfiguration()
      Gets the configuration store that the HttpClient will use.
      Returns:
      The configuration store to use.
    • setConnectTimeout

      public HttpClientOptions setConnectTimeout(Duration connectTimeout)
      Sets the connection timeout for a request to be sent.

      The connection timeout begins once the request attempts to connect to the remote host and finishes when the connection is resolved.

      If connectTimeout is null either Configuration.PROPERTY_AZURE_REQUEST_CONNECT_TIMEOUT or a 10-second timeout will be used, if it is a Duration less than or equal to zero then no timeout will be applied. When applying the timeout the greatest of one millisecond and the value of connectTimeout will be used.

      By default the connection timeout is 10 seconds.

      Parameters:
      connectTimeout - Connect timeout duration.
      Returns:
      The updated HttpClientOptions object.
    • getConnectTimeout

      public Duration getConnectTimeout()
      Gets the connection timeout for a request to be sent.

      By default the connection timeout is 10 seconds.

      Returns:
      The connection timeout of a request to be sent.
    • setWriteTimeout

      public HttpClientOptions setWriteTimeout(Duration writeTimeout)
      Sets the writing timeout for a request to be sent.

      The writing timeout does not apply to the entire request but to each emission being sent over the wire. For example a request body which emits 10 8KB buffers will trigger 10 write operations, the outbound buffer will be periodically checked to determine if it is still draining.

      If writeTimeout is null either Configuration.PROPERTY_AZURE_REQUEST_WRITE_TIMEOUT or a 60-second timeout will be used, if it is a Duration less than or equal to zero then no write timeout will be applied. When applying the timeout the greatest of one millisecond and the value of writeTimeout will be used.

      By default the writing timeout is 60 seconds.

      Parameters:
      writeTimeout - Write operation timeout duration.
      Returns:
      The updated HttpClientOptions object.
    • getWriteTimeout

      public Duration getWriteTimeout()
      Gets the writing timeout for a request to be sent.

      By default the writing timeout is 60 seconds.

      Returns:
      The writing timeout of a request to be sent.
    • responseTimeout

      public HttpClientOptions responseTimeout(Duration responseTimeout)
      Sets the response timeout duration used when waiting for a server to reply.

      The response timeout begins once the request write completes and finishes once the first response read is triggered when the server response is received.

      If responseTimeout is null either Configuration.PROPERTY_AZURE_REQUEST_RESPONSE_TIMEOUT or a 60-second timeout will be used, if it is a Duration less than or equal to zero then no timeout will be applied to the response. When applying the timeout the greatest of one millisecond and the value of responseTimeout will be used.

      By default the response timeout is 60 seconds.

      Parameters:
      responseTimeout - Response timeout duration.
      Returns:
      The updated HttpClientOptions object.
    • setResponseTimeout

      public HttpClientOptions setResponseTimeout(Duration responseTimeout)
      Sets the response timeout duration used when waiting for a server to reply.

      The response timeout begins once the request write completes and finishes once the first response read is triggered when the server response is received.

      If responseTimeout is null either Configuration.PROPERTY_AZURE_REQUEST_RESPONSE_TIMEOUT or a 60-second timeout will be used, if it is a Duration less than or equal to zero then no timeout will be applied to the response. When applying the timeout the greatest of one millisecond and the value of responseTimeout will be used.

      By default the response timeout is 60 seconds.

      Parameters:
      responseTimeout - Response timeout duration.
      Returns:
      The updated HttpClientOptions object.
    • getResponseTimeout

      public Duration getResponseTimeout()
      Gets the response timeout duration used when waiting for a server to reply.

      By default the response timeout is 60 seconds.

      Returns:
      The response timeout duration.
    • readTimeout

      public HttpClientOptions readTimeout(Duration readTimeout)
      Sets the read timeout duration used when reading the server response.

      The read timeout begins once the first response read is triggered after the server response is received. This timeout triggers periodically but won't fire its operation if another read operation has completed between when the timeout is triggered and completes.

      If readTimeout is null either Configuration.PROPERTY_AZURE_REQUEST_READ_TIMEOUT or a 60-second timeout will be used, if it is a Duration less than or equal to zero then no timeout period will be applied to response read. When applying the timeout the greatest of one millisecond and the value of readTimeout will be used.

      By default the read timeout is 60 seconds.

      Parameters:
      readTimeout - Read timeout duration.
      Returns:
      The updated HttpClientOptions object.
    • setReadTimeout

      public HttpClientOptions setReadTimeout(Duration readTimeout)
      Sets the read timeout duration used when reading the server response.

      The read timeout begins once the first response read is triggered after the server response is received. This timeout triggers periodically but won't fire its operation if another read operation has completed between when the timeout is triggered and completes.

      If readTimeout is null either Configuration.PROPERTY_AZURE_REQUEST_READ_TIMEOUT or a 60-second timeout will be used, if it is a Duration less than or equal to zero then no timeout period will be applied to response read. When applying the timeout the greatest of one millisecond and the value of readTimeout will be used.

      By default the read timeout is 60 seconds.

      Parameters:
      readTimeout - Read timeout duration.
      Returns:
      The updated HttpClientOptions object.
    • getReadTimeout

      public Duration getReadTimeout()
      Gets the read timeout duration used when reading the server response.

      By default the read timeout is 60 seconds.

      Returns:
      The read timeout duration.
    • setMaximumConnectionPoolSize

      public HttpClientOptions setMaximumConnectionPoolSize(Integer maximumConnectionPoolSize)
      Sets the maximum connection pool size used by the underlying HTTP client.

      Modifying the maximum connection pool size may have effects on the performance of an application. Increasing the maximum connection pool will result in more connections being available for an application but may result in more contention for network resources. It is recommended to perform performance analysis on different maximum connection pool sizes to find the right configuration for an application.

      This maximum connection pool size is not a global configuration but an instance level configuration for each HttpClient created using this HttpClientOptions.

      By default the maximum connection pool size is determined by the underlying HTTP client. Setting the maximum connection pool size to null resets the configuration to use the default determined by the underlying HTTP client.

      Parameters:
      maximumConnectionPoolSize - The maximum connection pool size.
      Returns:
      The updated HttpClientOptions object.
      Throws:
      IllegalArgumentException - If maximumConnectionPoolSize is not null and is less than 1.
    • getMaximumConnectionPoolSize

      public Integer getMaximumConnectionPoolSize()
      Gets the maximum connection pool size used by the underlying HTTP client.

      Modifying the maximum connection pool size may have effects on the performance of an application. Increasing the maximum connection pool will result in more connections being available for an application but may result in more contention for network resources. It is recommended to perform performance analysis on different maximum connection pool sizes to find the right configuration for an application.

      This maximum connection pool size is not a global configuration but an instance level configuration for each HttpClient created using this HttpClientOptions.

      By default the maximum connection pool size is determined by the underlying HTTP client. Setting the maximum connection pool size to null resets the configuration to use the default determined by the underlying HTTP client.

      Returns:
      The maximum connection pool size.
    • setConnectionIdleTimeout

      public HttpClientOptions setConnectionIdleTimeout(Duration connectionIdleTimeout)
      Sets the duration of time before an idle connection.

      The connection idle timeout begins once the connection has completed its last network request. Every time the connection is used the idle timeout will reset.

      If connectionIdleTimeout is null a 60-second timeout will be used, if it is a Duration less than or equal to zero then no timeout period will be applied. When applying the timeout the greatest of one millisecond and the value of connectionIdleTimeout will be used.

      By default the connection idle timeout is 60 seconds.

      Parameters:
      connectionIdleTimeout - The connection idle timeout duration.
      Returns:
      The updated HttpClientOptions object.
    • getConnectionIdleTimeout

      public Duration getConnectionIdleTimeout()
      Gets the duration of time before an idle connection is closed.

      By default the connection idle timeout is 60 seconds.

      Returns:
      The connection idle timeout duration.