Dela via


HttpClientOptions Class

public final class HttpClientOptions
extends ClientOptions

General configuration options for HttpClient.

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

Constructor Summary

Constructor Description
HttpClientOptions()

Creates a new instance of HttpClientOptions.

Method Summary

Modifier and Type Method and Description
Configuration getConfiguration()

Gets the configuration store that the HttpClient will use.

Duration getConnectTimeout()

Gets the connection timeout for a request to be sent.

Duration getConnectionIdleTimeout()

Gets the duration of time before an idle connection is closed.

Class<> getHttpClientProvider()

Gets type of the HttpClientProvider implementation that should be used to construct an instance of HttpClient.

Integer getMaximumConnectionPoolSize()

Gets the maximum connection pool size used by the underlying HTTP client.

ProxyOptions getProxyOptions()

Gets the ProxyOptions that the HttpClient will use.

Duration getReadTimeout()

Gets the read timeout duration used when reading the server response.

Duration getResponseTimeout()

Gets the response timeout duration used when waiting for a server to reply.

Duration getWriteTimeout()

Gets the writing timeout for a request to be sent.

HttpClientOptions readTimeout(Duration readTimeout)

Sets the read timeout duration used when reading the server response.

HttpClientOptions responseTimeout(Duration responseTimeout)

Sets the response timeout duration used when waiting for a server to reply.

HttpClientOptions setApplicationId(String applicationId)

Sets the application ID.

HttpClientOptions setConfiguration(Configuration configuration)

Sets the configuration store that the HttpClient will use.

HttpClientOptions setConnectTimeout(Duration connectTimeout)

Sets the connection timeout for a request to be sent.

HttpClientOptions setConnectionIdleTimeout(Duration connectionIdleTimeout)

Sets the duration of time before an idle connection.

HttpClientOptions setHeaders(Iterable<Header> headers)

Sets the Header.

HttpClientOptions setHttpClientProvider(Class<? extends HttpClientProvider> httpClientProvider)

Sets the type of the HttpClientProvider implementation that should be used to construct an instance of HttpClient.

HttpClientOptions setMaximumConnectionPoolSize(Integer maximumConnectionPoolSize)

Sets the maximum connection pool size used by the underlying HTTP client.

HttpClientOptions setProxyOptions(ProxyOptions proxyOptions)

Sets the ProxyOptions that the HttpClient will use.

HttpClientOptions setReadTimeout(Duration readTimeout)

Sets the read timeout duration used when reading the server response.

HttpClientOptions setResponseTimeout(Duration responseTimeout)

Sets the response timeout duration used when waiting for a server to reply.

HttpClientOptions setWriteTimeout(Duration writeTimeout)

Sets the writing timeout for a request to be sent.

Methods inherited from ClientOptions

Methods inherited from java.lang.Object

Constructor Details

HttpClientOptions

public HttpClientOptions()

Creates a new instance of HttpClientOptions.

Method Details

getConfiguration

public Configuration getConfiguration()

Gets the configuration store that the HttpClient will use.

Returns:

The configuration store to use.

getConnectTimeout

public Duration getConnectTimeout()

Gets 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 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.

The default connection timeout is 10 seconds.

Returns:

The connection timeout of a request to be sent.

getConnectionIdleTimeout

public Duration getConnectionIdleTimeout()

Gets the duration of time before an idle connection is closed.

The default connection idle timeout is 60 seconds.

Returns:

The connection idle timeout duration.

getHttpClientProvider

public Class getHttpClientProvider()

Gets type of the HttpClientProvider implementation that should be used to construct an instance of HttpClient.

Returns:

The HttpClientProvider implementation used to create an instance of HttpClient.

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.

The default 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.

getProxyOptions

public ProxyOptions getProxyOptions()

Gets the ProxyOptions that the HttpClient will use.

Returns:

The proxy options to use.

getReadTimeout

public Duration getReadTimeout()

Gets the read timeout duration used when reading the server response.

The default read timeout is 60 seconds.

Returns:

The read timeout duration.

getResponseTimeout

public Duration getResponseTimeout()

Gets 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 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.

The default response timeout is 60 seconds.

Returns:

The response timeout duration.

getWriteTimeout

public Duration getWriteTimeout()

Gets 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 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.

The default writing timeout is 60 seconds.

Returns:

The writing timeout of a request to be sent.

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 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.

The default read timeout is 60 seconds.

Parameters:

readTimeout - Read timeout duration.

Returns:

The updated HttpClientOptions object.

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 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.

The default response timeout is 60 seconds.

Parameters:

responseTimeout - Response timeout duration.

Returns:

The updated HttpClientOptions object.

setApplicationId

public HttpClientOptions setApplicationId(String applicationId)

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:

HttpClientOptions.setApplicationId(String applicationId)

Parameters:

applicationId

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.

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 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.

The default connection timeout is 10 seconds.

Parameters:

connectTimeout - Connect timeout duration.

Returns:

The updated HttpClientOptions object.

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.

The default connection idle timeout is 60 seconds.

Parameters:

connectionIdleTimeout - The connection idle timeout duration.

Returns:

The updated HttpClientOptions object.

setHeaders

public HttpClientOptions setHeaders(Iterable

headers)

Sets the Header.

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:

HttpClientOptions.setHeaders(Iterable<Header> headers)

Parameters:

headers

setHttpClientProvider

public HttpClientOptions setHttpClientProvider(Class httpClientProvider)

Sets the type of the HttpClientProvider implementation that should be used to construct an instance of HttpClient. If the value isn't set or is an empty string the first HttpClientProvider resolved by ServiceLoader will be used to create an instance of HttpClient. If the value is set and doesn't match any HttpClientProvider resolved by ServiceLoader an IllegalStateException will be thrown when attempting to create an instance of HttpClient.

Parameters:

httpClientProvider - The HttpClientProvider implementation used to create an instance of HttpClient.

Returns:

The updated HttpClientOptions object.

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.

The default 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.

setProxyOptions

public HttpClientOptions setProxyOptions(ProxyOptions proxyOptions)

Sets the ProxyOptions that the HttpClient will use.

Parameters:

proxyOptions - The proxy options to use.

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 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.

The default read timeout is 60 seconds.

Parameters:

readTimeout - Read 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 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.

The default response timeout is 60 seconds.

Parameters:

responseTimeout - Response timeout duration.

Returns:

The updated HttpClientOptions object.

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 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.

The default writing timeout is 60 seconds.

Parameters:

writeTimeout - Write operation timeout duration.

Returns:

The updated HttpClientOptions object.

Applies to