Class HttpClientOptions
HttpClients
.
HttpClient
implementations may not support all configuration options in this class.
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionGets the configuration store that theHttpClient
will use.Gets the duration of time before an idle connection is closed.Gets the connection timeout for a request to be sent.Class<? extends HttpClientProvider>
Sets name of theHttpClientProvider
implementation that should be used to construct an instance ofHttpClient
.Gets the maximum connection pool size used by the underlying HTTP client.Gets theproxy options
that theHttpClient
will use.Gets the read timeout duration used when reading the server response.Gets the response timeout duration used when waiting for a server to reply.Gets the writing timeout for a request to be sent.readTimeout
(Duration readTimeout) Sets the read timeout duration used when reading the server response.responseTimeout
(Duration responseTimeout) Sets the response timeout duration used when waiting for a server to reply.setApplicationId
(String applicationId) Sets the application ID.setConfiguration
(Configuration configuration) Sets the configuration store that theHttpClient
will use.setConnectionIdleTimeout
(Duration connectionIdleTimeout) Sets the duration of time before an idle connection.setConnectTimeout
(Duration connectTimeout) Sets the connection timeout for a request to be sent.setHeaders
(Iterable<Header> headers) Sets theHeaders
.setHttpClientProvider
(Class<? extends HttpClientProvider> httpClientProvider) Sets the name of theHttpClientProvider
implementation that should be used to construct an instance ofHttpClient
.setMaximumConnectionPoolSize
(Integer maximumConnectionPoolSize) Sets the maximum connection pool size used by the underlying HTTP client.setProxyOptions
(ProxyOptions proxyOptions) Sets theproxy options
that theHttpClient
will use.setReadTimeout
(Duration readTimeout) Sets the read timeout duration used when reading the server response.setResponseTimeout
(Duration responseTimeout) Sets the response timeout duration used when waiting for a server to reply.setWriteTimeout
(Duration writeTimeout) Sets the writing timeout for a request to be sent.Methods inherited from class com.azure.core.util.ClientOptions
getApplicationId, getHeaders, getMetricsOptions, getTracingOptions, setMetricsOptions, setTracingOptions
-
Constructor Details
-
HttpClientOptions
public HttpClientOptions()Creates a new instance ofHttpClientOptions
.
-
-
Method Details
-
setApplicationId
Description copied from class:ClientOptions
Sets the application ID.The
applicationId
is used to configureUserAgentPolicy
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 classClientOptions
- Parameters:
applicationId
- The application ID.- Returns:
- The updated ClientOptions object.
-
setHeaders
Description copied from class:ClientOptions
Sets theHeaders
.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 classClientOptions
- Parameters:
headers
- The headers.- Returns:
- The updated
ClientOptions
object.
-
setProxyOptions
Sets theproxy options
that theHttpClient
will use.- Parameters:
proxyOptions
- The proxy options to use.- Returns:
- The updated HttpClientOptions object.
-
getProxyOptions
Gets theproxy options
that theHttpClient
will use.- Returns:
- The proxy options to use.
-
setConfiguration
Sets the configuration store that theHttpClient
will use.- Parameters:
configuration
- The configuration store to use.- Returns:
- The updated HttpClientOptions object.
-
getConfiguration
Gets the configuration store that theHttpClient
will use.- Returns:
- The configuration store to use.
-
setConnectTimeout
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 eitherConfiguration.PROPERTY_AZURE_REQUEST_CONNECT_TIMEOUT
or a 10-second timeout will be used, if it is aDuration
less than or equal to zero then no timeout will be applied. When applying the timeout the greatest of one millisecond and the value ofconnectTimeout
will be used.The default connection timeout is 10 seconds.
- Parameters:
connectTimeout
- Connect timeout duration.- Returns:
- The updated HttpClientOptions object.
-
getConnectTimeout
Gets the connection timeout for a request to be sent.The default connection timeout is 10 seconds.
- Returns:
- The connection timeout of a request to be sent.
-
setWriteTimeout
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 trigger10
write operations, the outbound buffer will be periodically checked to determine if it is still draining.If
writeTimeout
is null eitherConfiguration.PROPERTY_AZURE_REQUEST_WRITE_TIMEOUT
or a 60-second timeout will be used, if it is aDuration
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 ofwriteTimeout
will be used.The default writing timeout is 60 seconds.
- Parameters:
writeTimeout
- Write operation timeout duration.- Returns:
- The updated HttpClientOptions object.
-
getWriteTimeout
Gets the writing timeout for a request to be sent.The default writing timeout is 60 seconds.
- Returns:
- The writing timeout of a request to be sent.
-
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 eitherConfiguration.PROPERTY_AZURE_REQUEST_RESPONSE_TIMEOUT
or a 60-second timeout will be used, if it is aDuration
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 ofresponseTimeout
will be used.The default response timeout is 60 seconds.
- Parameters:
responseTimeout
- Response timeout duration.- Returns:
- The updated HttpClientOptions object.
-
setResponseTimeout
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 eitherConfiguration.PROPERTY_AZURE_REQUEST_RESPONSE_TIMEOUT
or a 60-second timeout will be used, if it is aDuration
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 ofresponseTimeout
will be used.The default response timeout is 60 seconds.
- Parameters:
responseTimeout
- Response timeout duration.- Returns:
- The updated HttpClientOptions object.
-
getResponseTimeout
Gets the response timeout duration used when waiting for a server to reply.The default response timeout is 60 seconds.
- Returns:
- The response timeout 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 eitherConfiguration.PROPERTY_AZURE_REQUEST_READ_TIMEOUT
or a 60-second timeout will be used, if it is aDuration
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 ofreadTimeout
will be used.The default read timeout is 60 seconds.
- Parameters:
readTimeout
- Read timeout duration.- Returns:
- The updated HttpClientOptions object.
-
setReadTimeout
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 eitherConfiguration.PROPERTY_AZURE_REQUEST_READ_TIMEOUT
or a 60-second timeout will be used, if it is aDuration
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 ofreadTimeout
will be used.The default read timeout is 60 seconds.
- Parameters:
readTimeout
- Read timeout duration.- Returns:
- The updated HttpClientOptions object.
-
getReadTimeout
Gets the read timeout duration used when reading the server response.The default read timeout is 60 seconds.
- Returns:
- The read timeout duration.
-
setMaximumConnectionPoolSize
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 thisHttpClientOptions
.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.
- Throws:
IllegalArgumentException
- IfmaximumConnectionPoolSize
is not null and is less than1
.
-
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 thisHttpClientOptions
.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.
-
setConnectionIdleTimeout
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 aDuration
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 ofconnectionIdleTimeout
will be used.The default connection idle timeout is 60 seconds.
- Parameters:
connectionIdleTimeout
- The connection idle timeout duration.- Returns:
- The updated HttpClientOptions object.
-
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.
-
setHttpClientProvider
public HttpClientOptions setHttpClientProvider(Class<? extends HttpClientProvider> httpClientProvider) Sets the name of theHttpClientProvider
implementation that should be used to construct an instance ofHttpClient
.The name must be the full class name, ex
com.azure.core.http.netty.NettyAsyncHttpClientProvider
and notNettyAsyncHttpClientProvider
, to disambiguate multiple providers with the same name but from different packages.If the value isn't set or is an empty string the first
HttpClientProvider
found on the class path will be used to create an instance ofHttpClient
. If the value is set and doesn't match anyHttpClientProvider
found on the class path anIllegalStateException
will be thrown when attempting to create an instance ofHttpClient
.- Parameters:
httpClientProvider
- TheHttpClientProvider
implementation used to create an instance ofHttpClient
.- Returns:
- The updated HttpClientOptions object.
-
getHttpClientProvider
Sets name of theHttpClientProvider
implementation that should be used to construct an instance ofHttpClient
.The name must be the full class name, ex
com.azure.core.http.netty.NettyAsyncHttpClientProvider
and notNettyAsyncHttpClientProvider
, to disambiguate multiple providers with the same name but from different packages.If the value isn't set or is an empty string the first
HttpClientProvider
found on the class path will be used to create an instance ofHttpClient
. If the value is set and doesn't match anyHttpClientProvider
found on the class path anIllegalStateException
will be thrown when attempting to create an instance ofHttpClient
.- Returns:
- The
HttpClientProvider
implementation used to create an instance ofHttpClient
.
-