Package io.micronaut.http.client
Class HttpClientConfiguration
java.lang.Object
io.micronaut.http.client.HttpClientConfiguration
- Direct Known Subclasses:
DefaultHttpClientConfiguration
,ServiceHttpClientConfiguration
Configuration for the
HttpClient
.- Since:
- 1.0
- Author:
- Graeme Rocher
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
Configuration for the HTTP client connnection pool.static class
Configuration for WebSocket client compression extensions. -
Field Summary
Modifier and TypeFieldDescriptionstatic final boolean
The default value.static final long
The default pool idle timeout in seconds.static final boolean
The default value.static final boolean
The default follow redirects value.static final int
The default max content length in bytes.static final long
The default read idle timeout in minutes.static final long
The default read timeout in seconds.static final long
The default shutdown timeout in millis.static final long
The default shutdown timeout in millis. -
Constructor Summary
ConstructorDescriptionDefault constructor.Copy constructor.HttpClientConfiguration
(ApplicationConfiguration applicationConfiguration) -
Method Summary
Modifier and TypeMethodDescriptionThe protocols to support for TLS ALPN.[available in the Netty HTTP client].Obtains the connection pool configuration.[available in the Netty HTTP client].[available in the Netty HTTP client].[available in the Netty HTTP client].[available in the Netty HTTP client].Deprecated.There are now separate settings for HTTP and HTTPS connections.[available in the Netty HTTP client].int
[available in the Netty HTTP client].[available in the Netty HTTP client].The connection mode to use for plaintext (http as opposed to https) connections.The proxy to use.The proxy to use.For streaming requests and WebSockets, thegetReadTimeout()
method does not apply instead a configurable idle timeout is applied.The amount of quiet period for shutdown.The amount of time to wait for shutdown.Optional<Class<? extends ThreadFactory>>
[available in the Netty HTTP client].Obtains the WebSocket compression configuration.boolean
Whether to allow blocking a netty event loop with a call toBlockingHttpClient
.boolean
boolean
resolveProxy
(boolean isSsl, String host, int port) Resolves a proxy to use for connection.void
setAllowBlockEventLoop
(boolean allowBlockEventLoop) Whether to allow blocking a netty event loop with a call toBlockingHttpClient
.void
setAlpnModes
(@NonNull List<String> alpnModes) The protocols to support for TLS ALPN.void
setChannelOptions
(Map<String, Object> channelOptions) void
setConnectionPoolIdleTimeout
(@Nullable Duration connectionPoolIdleTimeout) Sets the idle timeout for connection in the client connection pool.void
setConnectTimeout
(@Nullable Duration connectTimeout) Sets the connect timeout.void
setConnectTtl
(@Nullable Duration connectTtl) Sets the connect timeout.void
setDefaultCharset
(Charset defaultCharset) Sets the default charset to use.void
setEventLoopGroup
(@NonNull String eventLoopGroup) void
setExceptionOnErrorStatus
(boolean exceptionOnErrorStatus) Sets whether throwing an exception upon HTTP error status (>= 400) is preferred.void
setFollowRedirects
(boolean followRedirects) Sets whether redirects should be followed.void
setHttpVersion
(HttpVersion httpVersion) Deprecated.There are now separate settings for HTTP and HTTPS connections.void
setLoggerName
(@Nullable String loggerName) Sets the client-specific logger name.void
setLogLevel
(@Nullable LogLevel logLevel) Sets the level to enable trace logging at.void
setMaxContentLength
(int maxContentLength) Sets the maximum content length the client can consume.void
setNumOfThreads
(@Nullable Integer numOfThreads) Sets the number of threads the client should use for requests.void
setPlaintextMode
(HttpVersionSelection.PlaintextMode plaintextMode) The connection mode to use for plaintext (http as opposed to https) connections.void
setProxyAddress
(SocketAddress proxyAddress) Sets a proxy address.void
setProxyPassword
(String proxyPassword) Sets the proxy password.void
setProxySelector
(ProxySelector proxySelector) Sets the proxy selector.void
setProxyType
(Proxy.Type proxyType) void
setProxyUsername
(String proxyUsername) Sets the proxy username to use.void
setReadIdleTimeout
(@Nullable Duration readIdleTimeout) Sets the max read idle time for streaming requests.void
setReadTimeout
(@Nullable Duration readTimeout) Sets the read timeout.void
setShutdownQuietPeriod
(@Nullable Duration shutdownQuietPeriod) Sets the amount of quiet period for shutdown of client thread pools.void
setShutdownTimeout
(@Nullable Duration shutdownTimeout) Sets the amount of time to wait for shutdown of client thread pools.void
setSslConfiguration
(SslConfiguration sslConfiguration) Sets the SSL configuration for the client.void
setThreadFactory
(Class<? extends ThreadFactory> threadFactory) Sets a thread factory.
-
Field Details
-
DEFAULT_READ_TIMEOUT_SECONDS
public static final long DEFAULT_READ_TIMEOUT_SECONDSThe default read timeout in seconds.- See Also:
-
DEFAULT_READ_IDLE_TIMEOUT_MINUTES
public static final long DEFAULT_READ_IDLE_TIMEOUT_MINUTESThe default read idle timeout in minutes.- See Also:
-
DEFAULT_CONNECTION_POOL_IDLE_TIMEOUT_SECONDS
public static final long DEFAULT_CONNECTION_POOL_IDLE_TIMEOUT_SECONDSThe default pool idle timeout in seconds.- See Also:
-
DEFAULT_SHUTDOWN_QUIET_PERIOD_MILLISECONDS
public static final long DEFAULT_SHUTDOWN_QUIET_PERIOD_MILLISECONDSThe default shutdown timeout in millis.- See Also:
-
DEFAULT_SHUTDOWN_TIMEOUT_MILLISECONDS
public static final long DEFAULT_SHUTDOWN_TIMEOUT_MILLISECONDSThe default shutdown timeout in millis.- See Also:
-
DEFAULT_MAX_CONTENT_LENGTH
public static final int DEFAULT_MAX_CONTENT_LENGTHThe default max content length in bytes.- See Also:
-
DEFAULT_FOLLOW_REDIRECTS
public static final boolean DEFAULT_FOLLOW_REDIRECTSThe default follow redirects value.- See Also:
-
DEFAULT_EXCEPTION_ON_ERROR_STATUS
public static final boolean DEFAULT_EXCEPTION_ON_ERROR_STATUSThe default value.- See Also:
-
DEFAULT_ALLOW_BLOCK_EVENT_LOOP
public static final boolean DEFAULT_ALLOW_BLOCK_EVENT_LOOPThe default value.- See Also:
-
-
Constructor Details
-
HttpClientConfiguration
public HttpClientConfiguration()Default constructor. -
HttpClientConfiguration
- Parameters:
applicationConfiguration
- The application configuration
-
HttpClientConfiguration
Copy constructor.- Parameters:
copy
- The client configuration to copy settings from
-
-
Method Details
-
getHttpVersion
Deprecated.There are now separate settings for HTTP and HTTPS connections. To configure HTTP connections (e.g. for h2c), useplaintextMode
. To configure ALPN, setalpnModes
.The HTTP version to use. Defaults toHttpVersion.HTTP_1_1
.- Returns:
- The http version
-
setHttpVersion
Deprecated.There are now separate settings for HTTP and HTTPS connections. To configure HTTP connections (e.g. for h2c), useplaintextMode
. To configure ALPN, setalpnModes
.Sets the HTTP version to use. Defaults toHttpVersion.HTTP_1_1
.- Parameters:
httpVersion
- The http version
-
getLogLevel
[available in the Netty HTTP client].- Returns:
- The trace logging level
-
setLogLevel
Sets the level to enable trace logging at. Depending on the implementation this may activate additional handlers. For example in Netty this will activateLoggingHandler
at the given level.- Parameters:
logLevel
- The trace logging level
-
getEventLoopGroup
[available in the Netty HTTP client].- Returns:
- The event loop group to use.
-
setEventLoopGroup
- Parameters:
eventLoopGroup
- Sets the event loop group to use for the client.
-
getConnectionPoolConfiguration
public abstract HttpClientConfiguration.ConnectionPoolConfiguration getConnectionPoolConfiguration()Obtains the connection pool configuration.- Returns:
- The connection pool configuration.
-
getSslConfiguration
- Returns:
- The
SslConfiguration
for the client
-
setSslConfiguration
Sets the SSL configuration for the client.- Parameters:
sslConfiguration
- The SSL configuration
-
getWebSocketCompressionConfiguration
@Nullable public @Nullable HttpClientConfiguration.WebSocketCompressionConfiguration getWebSocketCompressionConfiguration()Obtains the WebSocket compression configuration.- Returns:
- The WebSocket compression configuration.
- Since:
- 4.3.0
-
isFollowRedirects
public boolean isFollowRedirects()- Returns:
- Whether redirects should be followed
-
isExceptionOnErrorStatus
public boolean isExceptionOnErrorStatus()- Returns:
- Whether throwing an exception upon HTTP error status (>= 400) is preferred.
-
setExceptionOnErrorStatus
public void setExceptionOnErrorStatus(boolean exceptionOnErrorStatus) Sets whether throwing an exception upon HTTP error status (>= 400) is preferred. Default value (DEFAULT_EXCEPTION_ON_ERROR_STATUS
)- Parameters:
exceptionOnErrorStatus
- Whether
-
getLoggerName
- Returns:
- The client-specific logger name if configured
-
setLoggerName
Sets the client-specific logger name.- Parameters:
loggerName
- The name of the logger.
-
setFollowRedirects
public void setFollowRedirects(boolean followRedirects) Sets whether redirects should be followed. Default value (DEFAULT_FOLLOW_REDIRECTS
).- Parameters:
followRedirects
- Whether redirects should be followed
-
getDefaultCharset
[available in the Netty HTTP client].- Returns:
- The default charset to use
-
setDefaultCharset
Sets the default charset to use. Default value (UTF-8);- Parameters:
defaultCharset
- The charset to use
-
getChannelOptions
[available in the Netty HTTP client].- Returns:
- The Client channel options.
-
setChannelOptions
- Parameters:
channelOptions
- The Client channel options
-
getReadTimeout
- Returns:
- The default read timeout. Defaults to 10 seconds.
-
getReadIdleTimeout
For streaming requests and WebSockets, thegetReadTimeout()
method does not apply instead a configurable idle timeout is applied. [available in the Netty HTTP client]- Returns:
- The default amount of time to allow read operation connections to remain idle
-
getConnectionPoolIdleTimeout
[available in the Netty HTTP client].- Returns:
- The idle timeout for connection in the client connection pool. Defaults to 0.
-
getConnectTimeout
- Returns:
- The default connect timeout. Defaults to Netty default.
-
getConnectTtl
[available in the Netty HTTP client].- Returns:
- The connectTtl.
-
getShutdownQuietPeriod
The amount of quiet period for shutdown. [available in the Netty HTTP client]- Returns:
- The shutdown timeout
-
getShutdownTimeout
The amount of time to wait for shutdown. [available in the Netty HTTP client]- Returns:
- The shutdown timeout
-
setShutdownQuietPeriod
Sets the amount of quiet period for shutdown of client thread pools. Default value (1L milliseconds). If a task is submitted during the quiet period, it will be accepted and the quiet period will start over.- Parameters:
shutdownQuietPeriod
- The shutdown quiet period
-
setShutdownTimeout
Sets the amount of time to wait for shutdown of client thread pools. Default value (100L milliseconds).- Parameters:
shutdownTimeout
- The shutdown time
-
setReadTimeout
Sets the read timeout. Default value (10L seconds).- Parameters:
readTimeout
- The read timeout
-
setReadIdleTimeout
Sets the max read idle time for streaming requests. Default value (5L minutes).- Parameters:
readIdleTimeout
- The read idle time
-
setConnectionPoolIdleTimeout
Sets the idle timeout for connection in the client connection pool. Defaults to 0.- Parameters:
connectionPoolIdleTimeout
- The connection pool idle timeout
-
setConnectTimeout
Sets the connect timeout.- Parameters:
connectTimeout
- The connect timeout
-
setConnectTtl
Sets the connect timeout.- Parameters:
connectTtl
- The connect timeout
-
getNumOfThreads
[available in the Netty HTTP client].- Returns:
- The number of threads the client should use for requests
-
setNumOfThreads
Sets the number of threads the client should use for requests.- Parameters:
numOfThreads
- The number of threads the client should use for requests
-
getThreadFactory
[available in the Netty HTTP client].- Returns:
- An
Optional
ThreadFactory
-
setThreadFactory
Sets a thread factory.- Parameters:
threadFactory
- The thread factory
-
getMaxContentLength
public int getMaxContentLength()[available in the Netty HTTP client].- Returns:
- The maximum content length the client can consume
-
setMaxContentLength
Sets the maximum content length the client can consume. Default value (10485760 => 10MB).- Parameters:
maxContentLength
- The maximum content length the client can consume
-
getProxyType
The proxy to use. For authentication specify http.proxyUser and http.proxyPassword system properties.
Alternatively configure a
java.net.ProxySelector
- Returns:
- The proxy type
-
setProxyType
- Parameters:
proxyType
- The proxy type
-
getProxyAddress
The proxy to use. For authentication specify http.proxyUser and http.proxyPassword system properties.Alternatively configure a
java.net.ProxySelector
- Returns:
- The optional proxy address
-
setProxyAddress
Sets a proxy address.- Parameters:
proxyAddress
- The proxy address
-
getProxyUsername
- Returns:
- The proxy username to use
-
setProxyUsername
Sets the proxy username to use.- Parameters:
proxyUsername
- The proxy username to use
-
getProxyPassword
- Returns:
- The proxy password to use.
-
setProxyPassword
Sets the proxy password.- Parameters:
proxyPassword
- The proxy password
-
setProxySelector
Sets the proxy selector. ProxySelector decides what proxy to use and take precedence oversetProxyAddress(SocketAddress)
andsetProxyType(Proxy.Type)
.- Parameters:
proxySelector
- The proxy selector to use
-
getProxySelector
- Returns:
- The proxy selector provided
-
resolveProxy
Resolves a proxy to use for connection.If ProxySelector is set by
setProxySelector(ProxySelector)
then it constructs URI and pass it toProxySelector.select(URI)
. First proxy returned by proxy selector will be used. If no proxy is returned by select, thenProxy.NO_PROXY
will be used.If ProxySelector is not set then parameters are ignored and a proxy as defined by
setProxyAddress(SocketAddress)
andsetProxyType(Proxy.Type)
will be returned. If no proxy is defined then parameters are ignored andProxy.NO_PROXY
is returned.- Parameters:
isSsl
- is it http or https connectionhost
- connection hostport
- connection port- Returns:
- A non null proxy instance
-
getPlaintextMode
The connection mode to use for plaintext (http as opposed to https) connections.
Note: IfhttpVersion
is set, this setting is ignored! [available in the Netty HTTP client].- Returns:
- The plaintext connection mode.
- Since:
- 4.0.0
-
setPlaintextMode
The connection mode to use for plaintext (http as opposed to https) connections.
Note: IfhttpVersion
is set, this setting is ignored!- Parameters:
plaintextMode
- The plaintext connection mode.- Since:
- 4.0.0
-
getAlpnModes
The protocols to support for TLS ALPN. If HTTP 2 is included, this will also restrict the TLS cipher suites to those supported by the HTTP 2 standard.
Note: IfhttpVersion
is set, this setting is ignored! [available in the Netty HTTP client].- Returns:
- The supported ALPN protocols.
- Since:
- 4.0.0
-
setAlpnModes
The protocols to support for TLS ALPN. If HTTP 2 is included, this will also restrict the TLS cipher suites to those supported by the HTTP 2 standard.
Note: IfhttpVersion
is set, this setting is ignored!- Parameters:
alpnModes
- The supported ALPN protocols.- Since:
- 4.0.0
-
isAllowBlockEventLoop
public boolean isAllowBlockEventLoop()Whether to allow blocking a netty event loop with a call toBlockingHttpClient
. When this is off (the default), any calls that block an event loop will throw an error. Such calls are almost always a mistake that can lead to hard-to-debug transient issues such as read timeouts. Only enable this setting if you are sure you won't hit such a bug.- Returns:
true
if blocking an event loop should be allowed
-
setAllowBlockEventLoop
public void setAllowBlockEventLoop(boolean allowBlockEventLoop) Whether to allow blocking a netty event loop with a call toBlockingHttpClient
. When this is off (the default), any calls that block an event loop will throw an error. Such calls are almost always a mistake that can lead to hard-to-debug transient issues such as read timeouts. Only enable this setting if you are sure you won't hit such a bug.
Default value: false- Parameters:
allowBlockEventLoop
-true
if blocking an event loop should be allowed
-