Class HttpClient
ClientTransport.connect()
is ultimately called.
Transfer-Encoding: chunked
will be applied for those HTTP methods for which
a request body is expected. Content-Length
provided via request headers
will disable Transfer-Encoding: chunked
.
Examples:
HttpClient.create() .baseUrl("https://example.com") .get() .response() .block();
HttpClient.create() .post() .uri("https://example.com") .send(Flux.just(bb1, bb2, bb3)) .responseSingle((res, content) -> Mono.just(res.status().code())) .block();
HttpClient.create() .baseUri("https://example.com") .post() .send(ByteBufFlux.fromString(flux)) .responseSingle((res, content) -> Mono.just(res.status().code())) .block();
- Author:
- Stephane Maldini, Violeta Georgieva
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interface
Marker interface for use withHttpClient.RequestSender.send(BiFunction)
.static interface
Allow a request body configuration before calling one of the terminal,Publisher
based,HttpClient.ResponseReceiver
API.static interface
HttpClient.ResponseReceiver<S extends HttpClient.ResponseReceiver<?>>
A response extractor for this configuredHttpClient
.static interface
HttpClient.UriConfiguration<S extends HttpClient.UriConfiguration<?>>
A URI configuration.static interface
Allow a websocket handling.static interface
Allow a request body configuration before calling one of the terminal,Publisher
based,HttpClient.WebsocketReceiver
API.Nested classes/interfaces inherited from class reactor.netty.transport.ClientTransport
ClientTransport.ResolvedAddressSelector<CONF>
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfinal HttpClient
Configure URI to use for this request/response.final HttpClient
compress
(boolean compressionEnabled) Specifies whether compression (gzip, Brotli, and zstd) is enabled.final HttpClient
Apply cookies configuration.final HttpClient
Deprecated.as of 1.1.0.final HttpClient
cookieCodec
(ClientCookieEncoder encoder) Deprecated.as of 1.1.0.final HttpClient
cookieCodec
(ClientCookieEncoder encoder, ClientCookieDecoder decoder) Deprecated.as of 1.1.0.final HttpClient
Apply cookies configuration emitted by the returned Mono before requesting.static HttpClient
create()
Prepare a pooledHttpClient
.static HttpClient
create
(ConnectionProvider connectionProvider) Prepare anHttpClient
.final HttpClient.RequestSender
delete()
HTTP DELETE to connect theHttpClient
.final HttpClient
disableRetry
(boolean disableRetry) Option to disableretry once
support for the outgoing requests that fail withAbortedException.isConnectionReset(Throwable)
.final HttpClient
doAfterRequest
(BiConsumer<? super HttpClientRequest, ? super Connection> doAfterRequest) Setup a callback called whenHttpClientRequest
has been sent andHttpClientState.REQUEST_SENT
has been emitted.final HttpClient
doAfterResponseSuccess
(BiConsumer<? super HttpClientResponse, ? super Connection> doAfterResponseSuccess) Setup a callback called afterHttpClientResponse
has been fully received andHttpClientState.RESPONSE_COMPLETED
has been emitted.final HttpClient
doOnError
(BiConsumer<? super HttpClientRequest, ? super Throwable> doOnRequestError, BiConsumer<? super HttpClientResponse, ? super Throwable> doOnResponseError) Setup a callback called whenHttpClientRequest
has not been sent and whenHttpClientResponse
has not been fully received.final HttpClient
doOnRedirect
(BiConsumer<? super HttpClientResponse, ? super Connection> doOnRedirect) Setup a callback called afterHttpClientResponse
headers have been received and the request is about to be redirected.final HttpClient
doOnRequest
(BiConsumer<? super HttpClientRequest, ? super Connection> doOnRequest) Setup a callback called whenHttpClientRequest
is about to be sent andHttpClientState.REQUEST_PREPARED
has been emitted.final HttpClient
doOnRequestError
(BiConsumer<? super HttpClientRequest, ? super Throwable> doOnRequestError) Setup a callback called whenHttpClientRequest
has not been sent.final HttpClient
doOnResponse
(BiConsumer<? super HttpClientResponse, ? super Connection> doOnResponse) Setup a callback called afterHttpClientResponse
headers have been received andHttpClientState.RESPONSE_RECEIVED
has been emitted.final HttpClient
doOnResponseError
(BiConsumer<? super HttpClientResponse, ? super Throwable> doOnResponseError) Setup a callback called whenHttpClientResponse
has not been fully received,HttpClientState.RESPONSE_INCOMPLETE
has been emitted.final HttpClient
followRedirect
(boolean followRedirect) Specifies whether HTTP status 301|302|303|307|308 auto-redirect support is enabled.final HttpClient
followRedirect
(boolean followRedirect, @Nullable BiConsumer<HttpHeaders, HttpClientRequest> redirectRequestBiConsumer) Variant offollowRedirect(boolean)
that also acceptsBiConsumer
that provides the headers from the previous request and the current redirect request.final HttpClient
followRedirect
(boolean followRedirect, @Nullable Consumer<HttpClientRequest> redirectRequestConsumer) Variant offollowRedirect(boolean)
that also accepts a redirect request processor.final HttpClient
followRedirect
(BiPredicate<HttpClientRequest, HttpClientResponse> predicate) Enables auto-redirect support if the passedPredicate
matches.final HttpClient
followRedirect
(BiPredicate<HttpClientRequest, HttpClientResponse> predicate, @Nullable BiConsumer<HttpHeaders, HttpClientRequest> redirectRequestBiConsumer) Variant offollowRedirect(BiPredicate)
that also acceptsBiConsumer
that provides the headers from the previous request and the current redirect request.final HttpClient
followRedirect
(BiPredicate<HttpClientRequest, HttpClientResponse> predicate, @Nullable Consumer<HttpClientRequest> redirectRequestConsumer) Variant offollowRedirect(BiPredicate)
that also accepts a redirect request processor.static HttpClient
Deprecated.Use the other methods exposed byHttpClient
to achieve the same configurations.final HttpClient.ResponseReceiver<?>
get()
HTTP GET to connect theHttpClient
.final HttpClient.ResponseReceiver<?>
head()
HTTP HEAD to connect theHttpClient
.final HttpClient
headers
(Consumer<? super HttpHeaders> headerBuilder) Apply headers configuration.final HttpClient
headersWhen
(Function<? super HttpHeaders, Mono<? extends HttpHeaders>> headerBuilder) Apply headers configuration emitted by the returned Mono before requesting.final HttpClient
http2Settings
(Consumer<Http2SettingsSpec.Builder> http2Settings) Apply HTTP/2 configuration.final HttpClient
http3Settings
(Consumer<Http3SettingsSpec.Builder> http3Settings) Apply HTTP/3 configuration.final HttpClient
httpMessageLogFactory
(HttpMessageLogFactory httpMessageLogFactory) WhenHttpMessage
is about to be logged the configured factory will be used for generating a sanitized log message.final HttpClient
httpResponseDecoder
(Function<HttpResponseDecoderSpec, HttpResponseDecoderSpec> responseDecoderOptions) Configure theHttpClientCodec
's response decoding options.final HttpClient
keepAlive
(boolean keepAlive) Enable or Disable Keep-Alive support for the outgoing request.final HttpClient
mapConnect
(Function<? super Mono<? extends Connection>, ? extends Mono<? extends Connection>> connector) Intercept the connection lifecycle and allows delaying, transform or inject a context.final HttpClient
Whether to enable metrics to be collected and registered in Micrometer'sglobalRegistry
under the nameMetrics.HTTP_CLIENT_PREFIX
.final HttpClient
metrics
(boolean enable, Supplier<? extends ChannelMetricsRecorder> recorder) Specifies whether the metrics are enabled on theTransport
.final HttpClient
metrics
(boolean enable, Supplier<? extends ChannelMetricsRecorder> recorder, Function<String, String> uriValue) Specifies whether the metrics are enabled on theHttpClient
.static HttpClient
Prepare an unpooledHttpClient
.final HttpClient
noSSL()
Removes any previously applied SSL configuration customization.final HttpClient
observe
(ConnectionObserver observer) Set or add the givenConnectionObserver
to observe the connection state changes.final HttpClient.ResponseReceiver<?>
options()
HTTP OPTIONS to connect theHttpClient
.final HttpClient.RequestSender
patch()
HTTP PATCH to connect theHttpClient
.final HttpClient
port
(int port) The port to which this client should connect.final HttpClient.RequestSender
post()
HTTP POST to connect theHttpClient
.final HttpClient
protocol
(HttpProtocol... supportedProtocols) The HTTP protocol to support.final HttpClient
proxyWhen
(BiFunction<HttpClientConfig, ? super ProxyProvider.TypeSpec, Mono<? extends ProxyProvider.Builder>> proxyBuilder) Supports proxy configuration with a deferred approach.final HttpClient.RequestSender
put()
HTTP PUT to connect theHttpClient
.final HttpClient
remoteAddress
(Supplier<? extends SocketAddress> remoteAddressSupplier) The address to which this client should connect on each subscribe.request
(HttpMethod method) Use the passed HTTP method to connect theHttpClient
.final HttpClient
responseTimeout
(@Nullable Duration maxReadOperationInterval) Specifies the maximum duration allowed between each network-level read operation while reading a given response (resolution: ms).final HttpClient
secure()
Enable default sslContext support.final HttpClient
secure
(Consumer<? super SslProvider.SslContextSpec> sslProviderBuilder) Apply an SSL configuration customization via the passed builder.secure
(SslProvider sslProvider) Apply an SSL configuration via the passedSslProvider
.final HttpClient
tcpConfiguration
(Function<? super TcpClient, ? extends TcpClient> tcpMapper) Deprecated.Use the other methods exposed byHttpClient
to achieve the same configurations.warmup()
Based on the actual configuration, returns aMono
that triggers: an initialization of the event loop group an initialization of the host name resolver loads the necessary native libraries for the transport loads the necessary native libraries for the security if there is such By default, when method is not used, thefirst request
absorbs the extra time needed to load resources.HTTP Websocket to connect theHttpClient
.websocket
(WebsocketClientSpec websocketClientSpec) HTTP Websocket to connect theHttpClient
.final HttpClient
wiretap
(boolean enable) Apply or remove a wire logger configuration usingTransport
category (logger),DEBUG
logger level andAdvancedByteBufFormat.HEX_DUMP
forByteBuf
format, which means both events and content will be logged and the content will be in hex format.Methods inherited from class reactor.netty.transport.ClientTransport
connect, connectNow, connectNow, doAfterResolve, doOnConnect, doOnConnected, doOnDisconnected, doOnResolve, doOnResolveError, host, noProxy, proxy, proxyWithSystemProperties, resolvedAddressesSelector, resolver, resolver, runOn
Methods inherited from class reactor.netty.transport.Transport
attr, bindAddress, channelGroup, configuration, doOnChannelInit, duplicate, metrics, option, runOn, runOn, wiretap, wiretap, wiretap, wiretap
-
Field Details
-
USER_AGENT
-
-
Constructor Details
-
HttpClient
public HttpClient()
-
-
Method Details
-
create
Prepare a pooledHttpClient
.HttpClient.UriConfiguration.uri(String)
orbaseUrl(String)
should be invoked before a verbrequest(HttpMethod)
is selected.- Returns:
- a
HttpClient
-
create
Prepare anHttpClient
.HttpClient.UriConfiguration.uri(String)
orbaseUrl(String)
should be invoked before a verbrequest(HttpMethod)
is selected.- Parameters:
connectionProvider
- theConnectionProvider
to be used- Returns:
- a
HttpClient
-
from
Deprecated.Use the other methods exposed byHttpClient
to achieve the same configurations. This method will be removed in version 1.1.0.Prepare anHttpClient
Note: There isn't only one method that replaces this deprecated method. The configuration that can be done with this deprecated method, can also be done with the other methods exposed by
HttpClient
.Examples:
Configuration via the deprecated '.from(...)' method
HttpClient.from( TcpClient.attr(...) // configures the channel attributes .bindAddress(...) // configures the bind (local) address .channelGroup(...) // configures the channel group .doOnChannelInit(...) // configures the channel handler .doOnConnected(...) // configures the doOnConnected callback .doOnDisconnected(...) // configures the doOnDisconnected callback .metrics(...) // configures the metrics .observe() // configures the connection observer .option(...) // configures the channel options .proxy(...) // configures the proxy .remoteAddress(...) // configures the remote address .resolver(...) // configures the host names resolver .runOn(...) // configures the event loop group .secure() // configures the SSL .wiretap()) // configures the wire logging
Configuration via the other methods exposed by
HttpClient
HttpClient.attr(...) // configures the channel attributes .bindAddress(...) // configures the bind (local) address .channelGroup(...) // configures the channel group .doOnChannelInit(...) // configures the channel handler .doOnConnected(...) // configures the doOnConnected callback .doOnDisconnected(...) // configures the doOnDisconnected callback .metrics(...) // configures the metrics .observe() // configures the connection observer .option(...) // configures the channel options .proxy(...) // configures the proxy .remoteAddress(...) // configures the remote address .resolver(...) // configures the host names resolver .runOn(...) // configures the event loop group .secure() // configures the SSL .wiretap() // configures the wire logging
Wire logging in plain text
HttpClient.wiretap("logger", LogLevel.DEBUG, AdvancedByteBufFormat.TEXTUAL)
- Returns:
- a new
HttpClient
-
newConnection
Prepare an unpooledHttpClient
.HttpClient.UriConfiguration.uri(String)
orbaseUrl(String)
should be invoked after a verbrequest(HttpMethod)
is selected.- Returns:
- a
HttpClient
-
baseUrl
Configure URI to use for this request/response.Note: Configured
baseUrl
only applies when used withHttpClient.UriConfiguration.uri(String)
orHttpClient.UriConfiguration.uri(Mono)
.- Parameters:
baseUrl
- a default base url that can be fully sufficient for request or can be used to prepend futureHttpClient.UriConfiguration.uri(java.lang.String)
calls.- Returns:
- the appropriate sending or receiving contract
-
compress
Specifies whether compression (gzip, Brotli, and zstd) is enabled.Note: Brotli and zstd compressions require additional dependencies.
Note: For zstd compression, Accept-Encoding: zstd header needs to be added explicitly.
- Parameters:
compressionEnabled
- if true, compression (gzip, Brotli, and zstd) is enabled, otherwise disabled (default: false)- Returns:
- a new
HttpClient
-
cookie
Apply cookies configuration.- Parameters:
cookie
- a cookie to append to the request(s)- Returns:
- a new
HttpClient
-
cookie
Deprecated.as of 1.1.0. Usecookie(Cookie)
for configuring cookies. This will be removed in 2.0.0.Apply cookies configuration.- Parameters:
cookieBuilder
- the headerConsumer
to invoke before requesting- Returns:
- a new
HttpClient
-
cookieCodec
Deprecated.as of 1.1.0. This will be removed in 2.0.0 as Netty 5 supports only strict validation.Configure theClientCookieEncoder
,ClientCookieDecoder
will be chosen based on the encoder.- Parameters:
encoder
- the preferred ClientCookieEncoder- Returns:
- a new
HttpClient
-
cookieCodec
@Deprecated public final HttpClient cookieCodec(ClientCookieEncoder encoder, ClientCookieDecoder decoder) Deprecated.as of 1.1.0. This will be removed in 2.0.0 as Netty 5 supports only strict validation.Configure theClientCookieEncoder
andClientCookieDecoder
.- Parameters:
encoder
- the preferred ClientCookieEncoderdecoder
- the preferred ClientCookieDecoder- Returns:
- a new
HttpClient
-
cookiesWhen
public final HttpClient cookiesWhen(String name, Function<? super Cookie, Mono<? extends Cookie>> cookieBuilder) Apply cookies configuration emitted by the returned Mono before requesting.- Parameters:
cookieBuilder
- the cookiesFunction
to invoke before sending- Returns:
- a new
HttpClient
-
delete
HTTP DELETE to connect theHttpClient
.- Returns:
- a
HttpClient.RequestSender
ready to prepare the content for response
-
disableRetry
Option to disableretry once
support for the outgoing requests that fail withAbortedException.isConnectionReset(Throwable)
.By default this is set to false in which case
retry once
is enabled.- Parameters:
disableRetry
- true to disableretry once
, false to enable it- Returns:
- a new
HttpClient
- Since:
- 0.9.6
-
doAfterRequest
public final HttpClient doAfterRequest(BiConsumer<? super HttpClientRequest, ? super Connection> doAfterRequest) Setup a callback called whenHttpClientRequest
has been sent andHttpClientState.REQUEST_SENT
has been emitted.- Parameters:
doAfterRequest
- a callback called whenHttpClientRequest
has been sent- Returns:
- a new
HttpClient
-
doAfterResponseSuccess
public final HttpClient doAfterResponseSuccess(BiConsumer<? super HttpClientResponse, ? super Connection> doAfterResponseSuccess) Setup a callback called afterHttpClientResponse
has been fully received andHttpClientState.RESPONSE_COMPLETED
has been emitted.- Parameters:
doAfterResponseSuccess
- a callback called afterHttpClientResponse
has been fully received andHttpClientState.RESPONSE_COMPLETED
has been emitted.- Returns:
- a new
HttpClient
- Since:
- 0.9.5
-
doOnError
public final HttpClient doOnError(BiConsumer<? super HttpClientRequest, ? super Throwable> doOnRequestError, BiConsumer<? super HttpClientResponse, ? super Throwable> doOnResponseError) Setup a callback called whenHttpClientRequest
has not been sent and whenHttpClientResponse
has not been fully received.Note that some mutation of
HttpClientRequest
performed late in lifecycledoOnRequest(BiConsumer)
orHttpClient.RequestSender.send(BiFunction)
might not be visible if the error results from a connection failure.- Parameters:
doOnRequestError
- a consumer observing request failuresdoOnResponseError
- a consumer observing response failures- Returns:
- a new
HttpClient
-
doOnRedirect
public final HttpClient doOnRedirect(BiConsumer<? super HttpClientResponse, ? super Connection> doOnRedirect) Setup a callback called afterHttpClientResponse
headers have been received and the request is about to be redirected.Note: This callback applies only if auto-redirect is enabled, e.g. via
followRedirect(boolean)
.- Parameters:
doOnRedirect
- a callback called afterHttpClientResponse
headers have been received and the request is about to be redirected- Returns:
- a new
HttpClient
- Since:
- 0.9.6
-
doOnRequest
public final HttpClient doOnRequest(BiConsumer<? super HttpClientRequest, ? super Connection> doOnRequest) Setup a callback called whenHttpClientRequest
is about to be sent andHttpClientState.REQUEST_PREPARED
has been emitted.- Parameters:
doOnRequest
- a callback called whenHttpClientRequest
is about to be sent- Returns:
- a new
HttpClient
-
doOnRequestError
public final HttpClient doOnRequestError(BiConsumer<? super HttpClientRequest, ? super Throwable> doOnRequestError) Setup a callback called whenHttpClientRequest
has not been sent. Note that some mutation ofHttpClientRequest
performed late in lifecycledoOnRequest(BiConsumer)
orHttpClient.RequestSender.send(BiFunction)
might not be visible if the error results from a connection failure.- Parameters:
doOnRequestError
- a consumer observing request failures- Returns:
- a new
HttpClient
-
doOnResponse
public final HttpClient doOnResponse(BiConsumer<? super HttpClientResponse, ? super Connection> doOnResponse) Setup a callback called afterHttpClientResponse
headers have been received andHttpClientState.RESPONSE_RECEIVED
has been emitted.- Parameters:
doOnResponse
- a callback called afterHttpClientResponse
headers have been received- Returns:
- a new
HttpClient
-
doOnResponseError
public final HttpClient doOnResponseError(BiConsumer<? super HttpClientResponse, ? super Throwable> doOnResponseError) Setup a callback called whenHttpClientResponse
has not been fully received,HttpClientState.RESPONSE_INCOMPLETE
has been emitted.- Parameters:
doOnResponseError
- a consumer observing response failures- Returns:
- a new
HttpClient
-
followRedirect
Enables auto-redirect support if the passedPredicate
matches.Note: The passed
HttpClientRequest
andHttpClientResponse
should be considered read-only and the implement SHOULD NOT consume or write the request/response in this predicate.Note: The sensitive headers
followRedirect
are removed from the initialized request when redirecting to a different domain, they can be re-added viafollowRedirect(BiPredicate, Consumer)
.- Parameters:
predicate
- that returns true to enable auto-redirect support.- Returns:
- a new
HttpClient
-
followRedirect
public final HttpClient followRedirect(BiPredicate<HttpClientRequest, HttpClientResponse> predicate, @Nullable BiConsumer<HttpHeaders, HttpClientRequest> redirectRequestBiConsumer) Variant offollowRedirect(BiPredicate)
that also acceptsBiConsumer
that provides the headers from the previous request and the current redirect request.Note: The sensitive headers:
- Expect
- Cookie
- Authorization
- Proxy-Authorization
BiConsumer
.- Parameters:
predicate
- that returns true to enable auto-redirect support.redirectRequestBiConsumer
-BiConsumer
, invoked on redirects, after the redirect request has been initialized, in order to apply further changes such as add/remove headers and cookies; useHttpClientInfos.redirectedFrom()
to check the original and any number of subsequent redirect(s), including the one that is in progress. TheBiConsumer
provides the headers from the previous request and the current redirect request.- Returns:
- a new
HttpClient
- Since:
- 0.9.12
-
followRedirect
public final HttpClient followRedirect(BiPredicate<HttpClientRequest, HttpClientResponse> predicate, @Nullable Consumer<HttpClientRequest> redirectRequestConsumer) Variant offollowRedirect(BiPredicate)
that also accepts a redirect request processor.Note: The sensitive headers:
- Expect
- Cookie
- Authorization
- Proxy-Authorization
redirectRequestConsumer
.- Parameters:
predicate
- that returns true to enable auto-redirect support.redirectRequestConsumer
- redirect request consumer, invoked on redirects, after the redirect request has been initialized, in order to apply further changes such as add/remove headers and cookies; useHttpClientInfos.redirectedFrom()
to check the original and any number of subsequent redirect(s), including the one that is in progress.- Returns:
- a new
HttpClient
- Since:
- 0.9.5
-
followRedirect
Specifies whether HTTP status 301|302|303|307|308 auto-redirect support is enabled.Note: The sensitive headers
followRedirect
are removed from the initialized request when redirecting to a different domain, they can be re-added viafollowRedirect(boolean, Consumer)
.- Parameters:
followRedirect
- if true HTTP status 301|302|307|308 auto-redirect support is enabled, otherwise disabled (default: false).- Returns:
- a new
HttpClient
-
followRedirect
public final HttpClient followRedirect(boolean followRedirect, @Nullable BiConsumer<HttpHeaders, HttpClientRequest> redirectRequestBiConsumer) Variant offollowRedirect(boolean)
that also acceptsBiConsumer
that provides the headers from the previous request and the current redirect request.Note: The sensitive headers:
- Expect
- Cookie
- Authorization
- Proxy-Authorization
BiConsumer
.- Parameters:
followRedirect
- if true HTTP status 301|302|307|308 auto-redirect support is enabled, otherwise disabled (default: false).redirectRequestBiConsumer
-BiConsumer
, invoked on redirects, after the redirect request has been initialized, in order to apply further changes such as add/remove headers and cookies; useHttpClientInfos.redirectedFrom()
to check the original and any number of subsequent redirect(s), including the one that is in progress. TheBiConsumer
provides the headers from the previous request and the current redirect request.- Returns:
- a new
HttpClient
- Since:
- 0.9.12
-
followRedirect
public final HttpClient followRedirect(boolean followRedirect, @Nullable Consumer<HttpClientRequest> redirectRequestConsumer) Variant offollowRedirect(boolean)
that also accepts a redirect request processor.Note: The sensitive headers:
- Expect
- Cookie
- Authorization
- Proxy-Authorization
redirectRequestConsumer
.- Parameters:
followRedirect
- if true HTTP status 301|302|307|308 auto-redirect support is enabled, otherwise disabled (default: false).redirectRequestConsumer
- redirect request consumer, invoked on redirects, after the redirect request has been initialized, in order to apply further changes such as add/remove headers and cookies; useHttpClientInfos.redirectedFrom()
to check the original and any number of subsequent redirect(s), including the one that is in progress.- Returns:
- a new
HttpClient
- Since:
- 0.9.5
-
get
HTTP GET to connect theHttpClient
.- Returns:
- a
HttpClient.RequestSender
ready to consume for response
-
head
HTTP HEAD to connect theHttpClient
.- Returns:
- a
HttpClient.RequestSender
ready to consume for response
-
headers
Apply headers configuration.- Parameters:
headerBuilder
- the headerConsumer
to invoke before requesting- Returns:
- a new
HttpClient
-
headersWhen
public final HttpClient headersWhen(Function<? super HttpHeaders, Mono<? extends HttpHeaders>> headerBuilder) Apply headers configuration emitted by the returned Mono before requesting.- Parameters:
headerBuilder
- the headerFunction
to invoke before sending- Returns:
- a new
HttpClient
-
http2Settings
Apply HTTP/2 configuration.- Parameters:
http2Settings
- configuresHttp2SettingsSpec
before requesting- Returns:
- a new
HttpClient
-
http3Settings
@Incubating public final HttpClient http3Settings(Consumer<Http3SettingsSpec.Builder> http3Settings) Apply HTTP/3 configuration.- Parameters:
http3Settings
- configuresHttp3SettingsSpec
before requesting- Returns:
- a new
HttpClient
- Since:
- 1.2.0
-
httpMessageLogFactory
WhenHttpMessage
is about to be logged the configured factory will be used for generating a sanitized log message.Default to
ReactorNettyHttpMessageLogFactory
:- hides the query from the uri
- hides the headers values
- only
DecoderException
message is presented
- Parameters:
httpMessageLogFactory
- the factory for generating the log message- Returns:
- a new
HttpClient
- Since:
- 1.0.24
-
httpResponseDecoder
public final HttpClient httpResponseDecoder(Function<HttpResponseDecoderSpec, HttpResponseDecoderSpec> responseDecoderOptions) Configure theHttpClientCodec
's response decoding options.- Parameters:
responseDecoderOptions
- a function to mutate the provided Http response decoder options- Returns:
- a new
HttpClient
-
keepAlive
Enable or Disable Keep-Alive support for the outgoing request.- Parameters:
keepAlive
- true if keepAlive should be enabled (default: true)- Returns:
- a new
HttpClient
-
mapConnect
public final HttpClient mapConnect(Function<? super Mono<? extends Connection>, ? extends Mono<? extends Connection>> connector) Intercept the connection lifecycle and allows delaying, transform or inject a context.- Parameters:
connector
- A bi function mapping the default connection and configured bootstrap to a target connection.- Returns:
- a new
HttpClient
-
metrics
Whether to enable metrics to be collected and registered in Micrometer'sglobalRegistry
under the nameMetrics.HTTP_CLIENT_PREFIX
.uriTagValue
function receives the actual uri and returns the uri tag value that will be used for the metrics withMetrics.URI
tag. For example instead of using the actual uri"/users/1"
as uri tag value, templated uri"/users/{id}"
can be used.Note: It is strongly recommended to provide template-like form for the URIs. Without a conversion to a template-like form, each distinct URI leads to the creation of a distinct tag, which takes a lot of memory for the metrics.
Note: It is strongly recommended applications to configure an upper limit for the number of the URI tags. For example:
Metrics.globalRegistry .config() .meterFilter(MeterFilter.maximumAllowableTags(HTTP_CLIENT_PREFIX, URI, 100, MeterFilter.deny()));
By default metrics are not enabled.
- Parameters:
enable
- true enables metrics collection; false disables ituriTagValue
- a function that receives the actual uri and returns the uri tag value that will be used for the metrics withMetrics.URI
tag- Returns:
- a new
HttpClient
- Since:
- 0.9.7
-
metrics
public final HttpClient metrics(boolean enable, Supplier<? extends ChannelMetricsRecorder> recorder) Description copied from class:Transport
Specifies whether the metrics are enabled on theTransport
. All generated metrics are provided to the specified recorder which is only instantiated if metrics are being enabled (the instantiation is not lazy, but happens immediately, while configuring theTransport
).- Overrides:
metrics
in classTransport<HttpClient,
HttpClientConfig> - Parameters:
enable
- if true enables the metrics on theTransport
.recorder
- a supplier for theChannelMetricsRecorder
- Returns:
- a new
Transport
reference
-
metrics
public final HttpClient metrics(boolean enable, Supplier<? extends ChannelMetricsRecorder> recorder, Function<String, String> uriValue) Specifies whether the metrics are enabled on theHttpClient
. All generated metrics are provided to the specified recorder which is only instantiated if metrics are being enabled (the instantiation is not lazy, but happens immediately, while configuring theHttpClient
).uriValue
function receives the actual uri and returns the uri value that will be used when the metrics are propagated to the recorder. For example instead of using the actual uri"/users/1"
as uri value, templated uri"/users/{id}"
can be used.- Parameters:
enable
- true enables metrics collection; false disables itrecorder
- a supplier for the metrics recorder that receives the collected metricsuriValue
- a function that receives the actual uri and returns the uri value that will be used when the metrics are propagated to the recorder.- Returns:
- a new
HttpClient
-
noSSL
Removes any previously applied SSL configuration customization.- Returns:
- a new
HttpClient
-
observe
Description copied from class:Transport
Set or add the givenConnectionObserver
to observe the connection state changes.- Overrides:
observe
in classTransport<HttpClient,
HttpClientConfig> - Parameters:
observer
- theConnectionObserver
to be set or add- Returns:
- a new
Transport
reference
-
options
HTTP OPTIONS to connect theHttpClient
.- Returns:
- a
HttpClient.RequestSender
ready to consume for response
-
patch
HTTP PATCH to connect theHttpClient
.- Returns:
- a
HttpClient.RequestSender
ready to finalize request and consume for response
-
port
The port to which this client should connect. If a port is not specified, the default port80
is used.Note: The port can be specified also with
PORT
environment variable.- Overrides:
port
in classClientTransport<HttpClient,
HttpClientConfig> - Parameters:
port
- the port to connect to- Returns:
- a new
HttpClient
-
post
HTTP POST to connect theHttpClient
.- Returns:
- a
HttpClient.RequestSender
ready to finalize request and consume for response
-
protocol
The HTTP protocol to support. Default isHttpProtocol.HTTP11
.- Parameters:
supportedProtocols
- The variousHttpProtocol
this client will support- Returns:
- a new
HttpClient
-
put
HTTP PUT to connect theHttpClient
.- Returns:
- a
HttpClient.RequestSender
ready to finalize request and consume for response
-
remoteAddress
Description copied from class:ClientTransport
The address to which this client should connect on each subscribe.- Overrides:
remoteAddress
in classClientTransport<HttpClient,
HttpClientConfig> - Parameters:
remoteAddressSupplier
- A supplier of the address to connect to.- Returns:
- a new
ClientTransport
-
request
Use the passed HTTP method to connect theHttpClient
.- Parameters:
method
- the HTTP method to send- Returns:
- a
HttpClient.RequestSender
ready to finalize request and consume for response
-
responseTimeout
Specifies the maximum duration allowed between each network-level read operation while reading a given response (resolution: ms). In other words,ReadTimeoutHandler
is added to the channel pipeline after sending the request and is removed when the response is fully received. If themaxReadOperationInterval
isnull
, any previous setting will be removed and nomaxReadOperationInterval
will be applied. If themaxReadOperationInterval
is less than1ms
, then1ms
will be themaxReadOperationInterval
. ThemaxReadOperationInterval
setting onHttpClientRequest
level overrides anymaxReadOperationInterval
setting onHttpClient
level.- Parameters:
maxReadOperationInterval
- the maximum duration allowed between each network-level read operations (resolution: ms).- Returns:
- a new
HttpClient
- Since:
- 0.9.11
- See Also:
-
secure
Enable default sslContext support.By default
SslContext
is initialized with:10
seconds handshake timeout unless the environment propertyreactor.netty.tcp.sslHandshakeTimeout
is set3
seconds close_notify flush timeout0
second close_notify read timeout- hostname verification enabled
- Returns:
- a new
HttpClient
-
secure
Apply an SSL configuration customization via the passed builder.The builder will produce the
SslContext
with:10
seconds handshake timeout unless the passed builder sets another configuration or the environment propertyreactor.netty.tcp.sslHandshakeTimeout
is set3
seconds close_notify flush timeout0
second close_notify read timeout- hostname verification enabled
- Parameters:
sslProviderBuilder
- builder callback for further customization of SslContext.- Returns:
- a new
HttpClient
-
secure
Apply an SSL configuration via the passedSslProvider
.Note: Hostname verification is not enabled by default. If hostname verification is needed, please apply the
HttpClientSecurityUtils.HOSTNAME_VERIFICATION_CONFIGURER
configuration to theSslProvider
:SslProvider.builder() .sslContext(...) .handlerConfigurator(HttpClientSecurityUtils.HOSTNAME_VERIFICATION_CONFIGURER) .build();
- Parameters:
sslProvider
- The provider to set when configuring SSL- Returns:
- a new
HttpClient
-
tcpConfiguration
@Deprecated public final HttpClient tcpConfiguration(Function<? super TcpClient, ? extends TcpClient> tcpMapper) Deprecated.Use the other methods exposed byHttpClient
to achieve the same configurations. This method will be removed in version 1.1.0.Apply aTcpClient
mapping function to update TCP configuration and return an enrichedHttpClient
to use.Note: There isn't only one method that replaces this deprecated method. The configuration that can be done with this deprecated method, can also be done with the other methods exposed by
HttpClient
.Examples:
Configuration via the deprecated '.tcpConfiguration(...)' method
HttpClient.tcpConfiguration(tcpClient -> tcpClient.attr(...) // configures the channel attributes .bindAddress(...) // configures the bind (local) address .channelGroup(...) // configures the channel group .doOnChannelInit(...) // configures the channel handler .doOnConnected(...) // configures the doOnConnected callback .doOnDisconnected(...) // configures the doOnDisconnected callback .host(...) // configures the host name .metrics(...) // configures the metrics .noProxy() // removes proxy configuration .noSSL() // removes SSL configuration .observe() // configures the connection observer .option(...) // configures the channel options .port(...) // configures the port .proxy(...) // configures the proxy .remoteAddress(...) // configures the remote address .resolver(...) // configures the host names resolver .runOn(...) // configures the event loop group .secure() // configures the SSL .wiretap()) // configures the wire logging
Configuration via the other methods exposed by
HttpClient
HttpClient.attr(...) // configures the channel attributes .bindAddress(...) // configures the bind (local) address .channelGroup(...) // configures the channel group .doOnChannelInit(...) // configures the channel handler .doOnConnected(...) // configures the doOnConnected callback .doOnDisconnected(...) // configures the doOnDisconnected callback .host(...) // configures the host name .metrics(...) // configures the metrics .noProxy() // removes proxy configuration .noSSL() // removes SSL configuration .observe() // configures the connection observer .option(...) // configures the channel options .port(...) // configures the port .proxy(...) // configures the proxy .remoteAddress(...) // configures the remote address .resolver(...) // configures the host names resolver .runOn(...) // configures the event loop group .secure() // configures the SSL .wiretap() // configures the wire logging
Wire logging in plain text
HttpClient.wiretap("logger", LogLevel.DEBUG, AdvancedByteBufFormat.TEXTUAL)
- Parameters:
tcpMapper
- ATcpClient
mapping function to update TCP configuration and return an enrichedHttpClient
to use.- Returns:
- a new
HttpClient
-
warmup
Based on the actual configuration, returns aMono
that triggers:- an initialization of the event loop group
- an initialization of the host name resolver
- loads the necessary native libraries for the transport
- loads the necessary native libraries for the security if there is such
first request
absorbs the extra time needed to load resources.- Overrides:
warmup
in classClientTransport<HttpClient,
HttpClientConfig> - Returns:
- a
Mono
representing the completion of the warmup - Since:
- 1.0.3
-
proxyWhen
public final HttpClient proxyWhen(BiFunction<HttpClientConfig, ? super ProxyProvider.TypeSpec, Mono<? extends ProxyProvider.Builder>> proxyBuilder) Supports proxy configuration with a deferred approach.When proxyWhen(...) is set, calls to proxy(...) and noProxy() methods are ignored.
This method allows dynamic determination of proxy settings, applying or skipping the proxy based on the configured conditions.
- Parameters:
proxyBuilder
- a deferred builder for proxy configuration- Returns:
- a new
HttpClient
reference - Since:
- 1.2.3
-
websocket
HTTP Websocket to connect theHttpClient
.- Returns:
- a
HttpClient.WebsocketSender
ready to consume for response
-
websocket
HTTP Websocket to connect theHttpClient
.- Parameters:
websocketClientSpec
-WebsocketClientSpec
for websocket configuration- Returns:
- a
HttpClient.WebsocketSender
ready to consume for response - Since:
- 0.9.7
-
wiretap
Description copied from class:Transport
Apply or remove a wire logger configuration usingTransport
category (logger),DEBUG
logger level andAdvancedByteBufFormat.HEX_DUMP
forByteBuf
format, which means both events and content will be logged and the content will be in hex format.- Overrides:
wiretap
in classTransport<HttpClient,
HttpClientConfig> - Parameters:
enable
- specifies whether the wire logger configuration will be added to the pipeline- Returns:
- a new
Transport
reference
-