HttpClientOptions Class
- java.
lang. Object - com.
azure. core. util. ClientOptions - com.
azure. core. util. HttpClientOptions
- com.
- com.
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. |
Proxy |
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. |
Http |
readTimeout(Duration readTimeout)
Sets the read timeout duration used when reading the server response. |
Http |
responseTimeout(Duration responseTimeout)
Sets the response timeout duration used when waiting for a server to reply. |
Http |
setApplicationId(String applicationId)
Sets the application ID. |
Http |
setConfiguration(Configuration configuration)
Sets the configuration store that the HttpClient will use. |
Http |
setConnectTimeout(Duration connectTimeout)
Sets the connection timeout for a request to be sent. |
Http |
setConnectionIdleTimeout(Duration connectionIdleTimeout)
Sets the duration of time before an idle connection. |
Http |
setHeaders(Iterable<Header> headers)
Sets the Header. |
Http |
setHttpClientProvider(Class<? extends HttpClientProvider> httpClientProvider)
Sets the type of the HttpClientProvider implementation that should be used to construct an instance of HttpClient. |
Http |
setMaximumConnectionPoolSize(Integer maximumConnectionPoolSize)
Sets the maximum connection pool size used by the underlying HTTP client. |
Http |
setProxyOptions(ProxyOptions proxyOptions)
Sets the ProxyOptions that the HttpClient will use. |
Http |
setReadTimeout(Duration readTimeout)
Sets the read timeout duration used when reading the server response. |
Http |
setResponseTimeout(Duration responseTimeout)
Sets the response timeout duration used when waiting for a server to reply. |
Http |
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:
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:
getConnectionIdleTimeout
public Duration getConnectionIdleTimeout()
Gets the duration of time before an idle connection is closed.
The default connection idle timeout is 60 seconds.
Returns:
getHttpClientProvider
public Class getHttpClientProvider()
Gets type of the HttpClientProvider implementation that should be used to construct an instance of HttpClient.
Returns:
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:
getProxyOptions
public ProxyOptions getProxyOptions()
Gets the ProxyOptions that the HttpClient will use.
Returns:
getReadTimeout
public Duration getReadTimeout()
Gets the read timeout duration used when reading the server response.
The default read timeout is 60 seconds.
Returns:
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:
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:
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:
Returns:
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:
Returns:
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:
setConfiguration
public HttpClientOptions setConfiguration(Configuration configuration)
Sets the configuration store that the HttpClient will use.
Parameters:
Returns:
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:
Returns:
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:
Returns:
setHeaders
public HttpClientOptions setHeaders(Iterable
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:
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:
Returns:
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:
Returns:
setProxyOptions
public HttpClientOptions setProxyOptions(ProxyOptions proxyOptions)
Sets the ProxyOptions that the HttpClient will use.
Parameters:
Returns:
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:
Returns:
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:
Returns:
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:
Returns: