Class HttpClientOptions
HttpClients.
HttpClient implementations may not support all configuration options in this class.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionGets the configuration store that theHttpClientwill use.Gets the duration of time before an idle connection is closed.Gets the connection timeout for a request to be sent.Gets the maximum connection pool size used by the underlying HTTP client.Gets theproxy optionsthat theHttpClientwill 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 theHttpClientwill 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.setMaximumConnectionPoolSize(Integer maximumConnectionPoolSize) Sets the maximum connection pool size used by the underlying HTTP client.setProxyOptions(ProxyOptions proxyOptions) Sets theproxy optionsthat theHttpClientwill 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, setMetricsOptions
-
Constructor Details
-
HttpClientOptions
public HttpClientOptions()
-
-
Method Details
-
setApplicationId
Description copied from class:ClientOptionsSets the application ID.The
applicationIdis used to configureUserAgentPolicyfor 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:
setApplicationIdin classClientOptions- Parameters:
applicationId- The application ID.- Returns:
- The updated ClientOptions object.
-
setHeaders
Description copied from class:ClientOptionsSets 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:
setHeadersin classClientOptions- Parameters:
headers- The headers.- Returns:
- The updated
ClientOptionsobject.
-
setProxyOptions
Sets theproxy optionsthat theHttpClientwill use.- Parameters:
proxyOptions- The proxy options to use.- Returns:
- The updated HttpClientOptions object.
-
getProxyOptions
Gets theproxy optionsthat theHttpClientwill use.- Returns:
- The proxy options to use.
-
setConfiguration
Sets the configuration store that theHttpClientwill use.- Parameters:
configuration- The configuration store to use.- Returns:
- The updated HttpClientOptions object.
-
getConfiguration
Gets the configuration store that theHttpClientwill 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
connectTimeoutis null eitherConfiguration.PROPERTY_AZURE_REQUEST_CONNECT_TIMEOUTor a 10-second timeout will be used, if it is aDurationless than or equal to zero then no timeout will be applied. When applying the timeout the greatest of one millisecond and the value ofconnectTimeoutwill be used.By default the 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.By default the 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
108KBbuffers will trigger10write operations, the outbound buffer will be periodically checked to determine if it is still draining.If
writeTimeoutis null eitherConfiguration.PROPERTY_AZURE_REQUEST_WRITE_TIMEOUTor a 60-second timeout will be used, if it is aDurationless than or equal to zero then no write timeout will be applied. When applying the timeout the greatest of one millisecond and the value ofwriteTimeoutwill be used.By default the 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.By default the 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
responseTimeoutis null eitherConfiguration.PROPERTY_AZURE_REQUEST_RESPONSE_TIMEOUTor a 60-second timeout will be used, if it is aDurationless 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 ofresponseTimeoutwill be used.By default the 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
responseTimeoutis null eitherConfiguration.PROPERTY_AZURE_REQUEST_RESPONSE_TIMEOUTor a 60-second timeout will be used, if it is aDurationless 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 ofresponseTimeoutwill be used.By default the 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.By default the 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
readTimeoutis null eitherConfiguration.PROPERTY_AZURE_REQUEST_READ_TIMEOUTor a 60-second timeout will be used, if it is aDurationless 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 ofreadTimeoutwill be used.By default the 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
readTimeoutis null eitherConfiguration.PROPERTY_AZURE_REQUEST_READ_TIMEOUTor a 60-second timeout will be used, if it is aDurationless 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 ofreadTimeoutwill be used.By default the 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.By default the 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
HttpClientcreated using thisHttpClientOptions.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- IfmaximumConnectionPoolSizeis 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
HttpClientcreated using thisHttpClientOptions.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
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
connectionIdleTimeoutis null a 60-second timeout will be used, if it is aDurationless than or equal to zero then no timeout period will be applied. When applying the timeout the greatest of one millisecond and the value ofconnectionIdleTimeoutwill be used.By default the 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.By default the connection idle timeout is 60 seconds.
- Returns:
- The connection idle timeout duration.
-