public abstract class HttpClient extends ClientTransport<HttpClient,HttpClientConfig>
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();
Modifier and Type | Class and Description |
---|---|
static interface |
HttpClient.RedirectSendHandler
Marker interface for use with
HttpClient.RequestSender.send(BiFunction) . |
static interface |
HttpClient.RequestSender
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 configured
HttpClient . |
static interface |
HttpClient.UriConfiguration<S extends HttpClient.UriConfiguration<?>>
A URI configuration
|
static interface |
HttpClient.WebsocketReceiver<S extends HttpClient.WebsocketReceiver<?>>
Allow a websocket handling.
|
static interface |
HttpClient.WebsocketSender
Allow a request body configuration before calling one of the terminal,
Publisher based, HttpClient.WebsocketReceiver API. |
Modifier and Type | Field and Description |
---|---|
static String |
USER_AGENT |
Constructor and Description |
---|
HttpClient() |
Modifier and Type | Method and Description |
---|---|
HttpClient |
baseUrl(String baseUrl)
Configure URI to use for this request/response.
|
HttpClient |
compress(boolean compressionEnabled)
Specifies whether GZip compression is enabled.
|
HttpClient |
cookie(Cookie cookie)
Apply cookies configuration.
|
HttpClient |
cookie(String name,
Consumer<? super Cookie> cookieBuilder)
Apply cookies configuration.
|
HttpClient |
cookieCodec(ClientCookieEncoder encoder)
Configure the
ClientCookieEncoder , ClientCookieDecoder will be
chosen based on the encoder |
HttpClient |
cookieCodec(ClientCookieEncoder encoder,
ClientCookieDecoder decoder)
Configure the
ClientCookieEncoder and ClientCookieDecoder |
HttpClient |
cookiesWhen(String name,
Function<? super Cookie,Mono<? extends Cookie>> cookieBuilder)
Apply cookies configuration emitted by the returned Mono before requesting.
|
static HttpClient |
create()
Prepare a pooled
HttpClient . |
static HttpClient |
create(ConnectionProvider connectionProvider)
Prepare an
HttpClient . |
HttpClient.RequestSender |
delete()
HTTP DELETE to connect the
HttpClient . |
HttpClient |
disableRetry(boolean disableRetry)
Option to disable
retry once support for the outgoing requests that fail with
AbortedException.isConnectionReset(Throwable) . |
HttpClient |
doAfterRequest(BiConsumer<? super HttpClientRequest,? super Connection> doAfterRequest)
Setup a callback called when
HttpClientRequest has been sent
and HttpClientState.REQUEST_SENT has been emitted. |
HttpClient |
doAfterResponseSuccess(BiConsumer<? super HttpClientResponse,? super Connection> doAfterResponseSuccess)
Setup a callback called after
HttpClientResponse has been fully received
and HttpClientState.RESPONSE_COMPLETED has been emitted. |
HttpClient |
doOnError(BiConsumer<? super HttpClientRequest,? super Throwable> doOnRequestError,
BiConsumer<? super HttpClientResponse,? super Throwable> doOnResponseError)
Setup a callback called when
HttpClientRequest has not been sent and when HttpClientResponse has not been fully
received. |
HttpClient |
doOnRedirect(BiConsumer<? super HttpClientResponse,? super Connection> doOnRedirect)
Setup a callback called after
HttpClientResponse headers have been
received and the request is about to be redirected. |
HttpClient |
doOnRequest(BiConsumer<? super HttpClientRequest,? super Connection> doOnRequest)
Setup a callback called when
HttpClientRequest is about to be sent
and HttpClientState.REQUEST_PREPARED has been emitted. |
HttpClient |
doOnRequestError(BiConsumer<? super HttpClientRequest,? super Throwable> doOnRequestError)
Setup a callback called when
HttpClientRequest has not been sent. |
HttpClient |
doOnResponse(BiConsumer<? super HttpClientResponse,? super Connection> doOnResponse)
Setup a callback called after
HttpClientResponse headers have been
received and HttpClientState.RESPONSE_RECEIVED has been emitted. |
HttpClient |
doOnResponseError(BiConsumer<? super HttpClientResponse,? super Throwable> doOnResponseError)
Setup a callback called when
HttpClientResponse has not been fully
received, HttpClientState.RESPONSE_INCOMPLETE has been emitted. |
HttpClient |
followRedirect(BiPredicate<HttpClientRequest,HttpClientResponse> predicate)
Enables auto-redirect support if the passed
Predicate matches. |
HttpClient |
followRedirect(BiPredicate<HttpClientRequest,HttpClientResponse> predicate,
BiConsumer<HttpHeaders,HttpClientRequest> redirectRequestBiConsumer)
Variant of
followRedirect(BiPredicate) that also accepts
BiConsumer that provides the headers from the previous request and the current redirect request. |
HttpClient |
followRedirect(BiPredicate<HttpClientRequest,HttpClientResponse> predicate,
Consumer<HttpClientRequest> redirectRequestConsumer)
Variant of
followRedirect(BiPredicate) that also accepts a redirect request
processor. |
HttpClient |
followRedirect(boolean followRedirect)
Specifies whether HTTP status 301|302|307|308 auto-redirect support is enabled.
|
HttpClient |
followRedirect(boolean followRedirect,
BiConsumer<HttpHeaders,HttpClientRequest> redirectRequestBiConsumer)
Variant of
followRedirect(boolean) that also accepts
BiConsumer that provides the headers from the previous request and the current redirect request. |
HttpClient |
followRedirect(boolean followRedirect,
Consumer<HttpClientRequest> redirectRequestConsumer)
Variant of
followRedirect(boolean) that also accepts a redirect request
processor. |
static HttpClient |
from(TcpClient tcpClient)
Deprecated.
Use the other methods exposed by
HttpClient to achieve the same configurations.
This method will be removed in version 1.1.0. |
HttpClient.ResponseReceiver<?> |
get()
HTTP GET to connect the
HttpClient . |
HttpClient.ResponseReceiver<?> |
head()
HTTP HEAD to connect the
HttpClient . |
HttpClient |
headers(Consumer<? super HttpHeaders> headerBuilder)
Apply headers configuration.
|
HttpClient |
headersWhen(Function<? super HttpHeaders,Mono<? extends HttpHeaders>> headerBuilder)
Apply headers configuration emitted by the returned Mono before requesting.
|
HttpClient |
http2Settings(Consumer<Http2SettingsSpec.Builder> http2Settings)
Apply HTTP/2 configuration
|
HttpClient |
httpResponseDecoder(Function<HttpResponseDecoderSpec,HttpResponseDecoderSpec> responseDecoderOptions)
Configure the
HttpClientCodec 's response decoding options. |
HttpClient |
keepAlive(boolean keepAlive)
Enable or Disable Keep-Alive support for the outgoing request.
|
HttpClient |
mapConnect(Function<? super Mono<? extends Connection>,? extends Mono<? extends Connection>> connector)
Intercept the connection lifecycle and allows to delay, transform or inject a
context.
|
HttpClient |
metrics(boolean enable,
Function<String,String> uriTagValue)
Whether to enable metrics to be collected and registered in Micrometer's
globalRegistry
under the name Metrics.HTTP_CLIENT_PREFIX . |
HttpClient |
metrics(boolean enable,
Supplier<? extends ChannelMetricsRecorder> recorder)
Specifies whether the metrics are enabled on the
Transport . |
HttpClient |
metrics(boolean enable,
Supplier<? extends ChannelMetricsRecorder> recorder,
Function<String,String> uriValue)
Specifies whether the metrics are enabled on the
HttpClient . |
static HttpClient |
newConnection()
Prepare an unpooled
HttpClient . |
HttpClient |
noSSL()
Removes any previously applied SSL configuration customization
|
HttpClient |
observe(ConnectionObserver observer)
Set or add the given
ConnectionObserver to observe the connection state changes. |
HttpClient.ResponseReceiver<?> |
options()
HTTP OPTIONS to connect the
HttpClient . |
HttpClient.RequestSender |
patch()
HTTP PATCH to connect the
HttpClient . |
HttpClient |
port(int port)
The port to which this client should connect.
|
HttpClient.RequestSender |
post()
HTTP POST to connect the
HttpClient . |
HttpClient |
protocol(HttpProtocol... supportedProtocols)
The HTTP protocol to support.
|
HttpClient.RequestSender |
put()
HTTP PUT to connect the
HttpClient . |
HttpClient |
remoteAddress(Supplier<? extends SocketAddress> remoteAddressSupplier)
The address to which this client should connect on each subscribe.
|
HttpClient.RequestSender |
request(HttpMethod method)
Use the passed HTTP method to connect the
HttpClient . |
HttpClient |
responseTimeout(Duration maxReadOperationInterval)
Specifies the maximum duration allowed between each network-level read operation while reading a given response
(resolution: ms).
|
HttpClient |
secure()
Enable default sslContext support.
|
HttpClient |
secure(Consumer<? super SslProvider.SslContextSpec> sslProviderBuilder)
Apply an SSL configuration customization via the passed builder.
|
HttpClient |
secure(SslProvider sslProvider)
Apply an SSL configuration via the passed
SslProvider . |
HttpClient |
tcpConfiguration(Function<? super TcpClient,? extends TcpClient> tcpMapper)
Deprecated.
Use the other methods exposed by
HttpClient to achieve the same configurations.
This method will be removed in version 1.1.0. |
Mono<Void> |
warmup()
Based on the actual configuration, returns a
Mono 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, the first request absorbs the extra time needed to load resources. |
HttpClient.WebsocketSender |
websocket()
HTTP Websocket to connect the
HttpClient . |
HttpClient.WebsocketSender |
websocket(WebsocketClientSpec websocketClientSpec)
HTTP Websocket to connect the
HttpClient . |
HttpClient |
wiretap(boolean enable)
Apply or remove a wire logger configuration using
Transport category (logger),
DEBUG logger level and AdvancedByteBufFormat.HEX_DUMP for ByteBuf format,
which means both events and content will be logged and the content will be in hex format. |
connect, connectNow, connectNow, doAfterResolve, doOnConnect, doOnConnected, doOnDisconnected, doOnResolve, doOnResolveError, host, noProxy, proxy, proxyWithSystemProperties, resolver, resolver, runOn
attr, bindAddress, channelGroup, configuration, doOnChannelInit, duplicate, metrics, option, runOn, runOn, wiretap, wiretap, wiretap, wiretap
public static final String USER_AGENT
public static HttpClient create()
HttpClient
. HttpClient.UriConfiguration.uri(String)
or
baseUrl(String)
should be invoked before a verb
request(HttpMethod)
is selected.HttpClient
public static HttpClient create(ConnectionProvider connectionProvider)
HttpClient
. HttpClient.UriConfiguration.uri(String)
or
baseUrl(String)
should be invoked before a verb
request(HttpMethod)
is selected.connectionProvider
- the ConnectionProvider
to be usedHttpClient
@Deprecated public static HttpClient from(TcpClient tcpClient)
HttpClient
to achieve the same configurations.
This method will be removed in version 1.1.0.HttpClient
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)
HttpClient
public static HttpClient newConnection()
HttpClient
. HttpClient.UriConfiguration.uri(String)
or
baseUrl(String)
should be invoked after a verb
request(HttpMethod)
is selected.HttpClient
public final HttpClient baseUrl(String baseUrl)
Note: Configured baseUrl
only applies when used with HttpClient.UriConfiguration.uri(String)
or HttpClient.UriConfiguration.uri(Mono)
.
baseUrl
- a default base url that can be fully sufficient for request or can
be used to prepend future HttpClient.UriConfiguration.uri(java.lang.String)
calls.public final HttpClient compress(boolean compressionEnabled)
compressionEnabled
- if true GZip compression is enabled otherwise disabled (default: false)HttpClient
public final HttpClient cookie(Cookie cookie)
cookie
- a cookie to append to the request(s)HttpClient
public final HttpClient cookie(String name, Consumer<? super Cookie> cookieBuilder)
cookieBuilder
- the header Consumer
to invoke before requestingHttpClient
public final HttpClient cookieCodec(ClientCookieEncoder encoder)
ClientCookieEncoder
, ClientCookieDecoder
will be
chosen based on the encoderencoder
- the preferred ClientCookieEncoderHttpClient
public final HttpClient cookieCodec(ClientCookieEncoder encoder, ClientCookieDecoder decoder)
ClientCookieEncoder
and ClientCookieDecoder
encoder
- the preferred ClientCookieEncoderdecoder
- the preferred ClientCookieDecoderHttpClient
public final HttpClient cookiesWhen(String name, Function<? super Cookie,Mono<? extends Cookie>> cookieBuilder)
cookieBuilder
- the cookies Function
to invoke before sendingHttpClient
public final HttpClient.RequestSender delete()
HttpClient
.HttpClient.RequestSender
ready to prepare the content for responsepublic final HttpClient disableRetry(boolean disableRetry)
retry once
support for the outgoing requests that fail with
AbortedException.isConnectionReset(Throwable)
.
By default this is set to false in which case retry once
is enabled.
disableRetry
- true to disable retry once
, false to enable itHttpClient
public final HttpClient doAfterRequest(BiConsumer<? super HttpClientRequest,? super Connection> doAfterRequest)
HttpClientRequest
has been sent
and HttpClientState.REQUEST_SENT
has been emitted.doAfterRequest
- a callback called when HttpClientRequest
has been sentHttpClient
public final HttpClient doAfterResponseSuccess(BiConsumer<? super HttpClientResponse,? super Connection> doAfterResponseSuccess)
HttpClientResponse
has been fully received
and HttpClientState.RESPONSE_COMPLETED
has been emitted.doAfterResponseSuccess
- a callback called after HttpClientResponse
has been fully received
and HttpClientState.RESPONSE_COMPLETED
has been emitted.HttpClient
public final HttpClient doOnError(BiConsumer<? super HttpClientRequest,? super Throwable> doOnRequestError, BiConsumer<? super HttpClientResponse,? super Throwable> doOnResponseError)
HttpClientRequest
has not been sent and when HttpClientResponse
has not been fully
received.
Note that some mutation of HttpClientRequest
performed late in lifecycle
doOnRequest(BiConsumer)
or HttpClient.RequestSender.send(BiFunction)
might
not be visible if the error results from a connection failure.
doOnRequestError
- a consumer observing request failuresdoOnResponseError
- a consumer observing response failuresHttpClient
public final HttpClient doOnRedirect(BiConsumer<? super HttpClientResponse,? super Connection> doOnRedirect)
HttpClientResponse
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)
.
doOnRedirect
- a callback called after HttpClientResponse
headers have been received
and the request is about to be redirectedHttpClient
public final HttpClient doOnRequest(BiConsumer<? super HttpClientRequest,? super Connection> doOnRequest)
HttpClientRequest
is about to be sent
and HttpClientState.REQUEST_PREPARED
has been emitted.doOnRequest
- a callback called when HttpClientRequest
is about to be sentHttpClient
public final HttpClient doOnRequestError(BiConsumer<? super HttpClientRequest,? super Throwable> doOnRequestError)
HttpClientRequest
has not been sent.
Note that some mutation of HttpClientRequest
performed late in lifecycle
doOnRequest(BiConsumer)
or HttpClient.RequestSender.send(BiFunction)
might
not be visible if the error results from a connection failure.doOnRequestError
- a consumer observing request failuresHttpClient
public final HttpClient doOnResponse(BiConsumer<? super HttpClientResponse,? super Connection> doOnResponse)
HttpClientResponse
headers have been
received and HttpClientState.RESPONSE_RECEIVED
has been emitted.doOnResponse
- a callback called after HttpClientResponse
headers have been receivedHttpClient
public final HttpClient doOnResponseError(BiConsumer<? super HttpClientResponse,? super Throwable> doOnResponseError)
HttpClientResponse
has not been fully
received, HttpClientState.RESPONSE_INCOMPLETE
has been emitted.doOnResponseError
- a consumer observing response failuresHttpClient
public final HttpClient followRedirect(BiPredicate<HttpClientRequest,HttpClientResponse> predicate)
Predicate
matches.
Note: The passed HttpClientRequest
and HttpClientResponse
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
via followRedirect(BiPredicate, Consumer)
.
predicate
- that returns true to enable auto-redirect support.HttpClient
public final HttpClient followRedirect(BiPredicate<HttpClientRequest,HttpClientResponse> predicate, @Nullable BiConsumer<HttpHeaders,HttpClientRequest> redirectRequestBiConsumer)
followRedirect(BiPredicate)
that also accepts
BiConsumer
that provides the headers from the previous request and the current redirect request.
Note: The sensitive headers:
BiConsumer
.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; use HttpClientInfos.redirectedFrom()
to
check the original and any number of subsequent redirect(s), including the one that
is in progress. The BiConsumer
provides the headers from the previous request
and the current redirect request.HttpClient
public final HttpClient followRedirect(BiPredicate<HttpClientRequest,HttpClientResponse> predicate, @Nullable Consumer<HttpClientRequest> redirectRequestConsumer)
followRedirect(BiPredicate)
that also accepts a redirect request
processor.
Note: The sensitive headers:
redirectRequestConsumer
.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; use HttpClientInfos.redirectedFrom()
to
check the original and any number of subsequent redirect(s), including the one that
is in progress.HttpClient
public final HttpClient followRedirect(boolean followRedirect)
Note: The sensitive headers followRedirect
are removed from the initialized request when redirecting to a different domain, they can be re-added
via followRedirect(boolean, Consumer)
.
followRedirect
- if true HTTP status 301|302|307|308 auto-redirect support
is enabled, otherwise disabled (default: false).HttpClient
public final HttpClient followRedirect(boolean followRedirect, @Nullable BiConsumer<HttpHeaders,HttpClientRequest> redirectRequestBiConsumer)
followRedirect(boolean)
that also accepts
BiConsumer
that provides the headers from the previous request and the current redirect request.
Note: The sensitive headers:
BiConsumer
.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; use HttpClientInfos.redirectedFrom()
to
check the original and any number of subsequent redirect(s), including the one that
is in progress. The BiConsumer
provides the headers from the previous request
and the current redirect request.HttpClient
public final HttpClient followRedirect(boolean followRedirect, @Nullable Consumer<HttpClientRequest> redirectRequestConsumer)
followRedirect(boolean)
that also accepts a redirect request
processor.
Note: The sensitive headers:
redirectRequestConsumer
.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; use HttpClientInfos.redirectedFrom()
to
check the original and any number of subsequent redirect(s), including the one that
is in progress.HttpClient
public final HttpClient.ResponseReceiver<?> get()
HttpClient
.HttpClient.RequestSender
ready to consume for responsepublic final HttpClient.ResponseReceiver<?> head()
HttpClient
.HttpClient.RequestSender
ready to consume for responsepublic final HttpClient headers(Consumer<? super HttpHeaders> headerBuilder)
headerBuilder
- the header Consumer
to invoke before requestingHttpClient
public final HttpClient headersWhen(Function<? super HttpHeaders,Mono<? extends HttpHeaders>> headerBuilder)
headerBuilder
- the header Function
to invoke before sendingHttpClient
public final HttpClient http2Settings(Consumer<Http2SettingsSpec.Builder> http2Settings)
http2Settings
- configures Http2SettingsSpec
before requestingHttpClient
public final HttpClient httpResponseDecoder(Function<HttpResponseDecoderSpec,HttpResponseDecoderSpec> responseDecoderOptions)
HttpClientCodec
's response decoding options.responseDecoderOptions
- a function to mutate the provided Http response decoder optionsHttpClient
public final HttpClient keepAlive(boolean keepAlive)
keepAlive
- true if keepAlive should be enabled (default: true)HttpClient
public final HttpClient mapConnect(Function<? super Mono<? extends Connection>,? extends Mono<? extends Connection>> connector)
connector
- A bi function mapping the default connection and configured
bootstrap to a target connection.HttpClient
public final HttpClient metrics(boolean enable, Function<String,String> uriTagValue)
globalRegistry
under the name Metrics.HTTP_CLIENT_PREFIX
.
uriTagValue
function receives the actual uri and returns the uri tag value
that will be used for the metrics with Metrics.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 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.
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 with Metrics.URI
tagHttpClient
public final HttpClient metrics(boolean enable, Supplier<? extends ChannelMetricsRecorder> recorder)
Transport
Transport
.
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 the Transport
).metrics
in class Transport<HttpClient,HttpClientConfig>
enable
- if true enables the metrics on the Transport
.recorder
- a supplier for the ChannelMetricsRecorder
Transport
referencepublic final HttpClient metrics(boolean enable, Supplier<? extends ChannelMetricsRecorder> recorder, Function<String,String> uriValue)
HttpClient
.
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 the HttpClient
).
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.
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.HttpClient
public final HttpClient noSSL()
HttpClient
public final HttpClient observe(ConnectionObserver observer)
Transport
ConnectionObserver
to observe the connection state changes.observe
in class Transport<HttpClient,HttpClientConfig>
observer
- the ConnectionObserver
to be set or addTransport
referencepublic final HttpClient.ResponseReceiver<?> options()
HttpClient
.HttpClient.RequestSender
ready to consume for responsepublic final HttpClient.RequestSender patch()
HttpClient
.HttpClient.RequestSender
ready to finalize request and consume for responsepublic final HttpClient port(int port)
ClientTransport
port
in class ClientTransport<HttpClient,HttpClientConfig>
port
- the port to connect toClientTransport
referencepublic final HttpClient.RequestSender post()
HttpClient
.HttpClient.RequestSender
ready to finalize request and consume for responsepublic final HttpClient protocol(HttpProtocol... supportedProtocols)
HttpProtocol.HTTP11
.supportedProtocols
- The various HttpProtocol
this client will supportHttpClient
public final HttpClient.RequestSender put()
HttpClient
.HttpClient.RequestSender
ready to finalize request and consume for responsepublic final HttpClient remoteAddress(Supplier<? extends SocketAddress> remoteAddressSupplier)
ClientTransport
remoteAddress
in class ClientTransport<HttpClient,HttpClientConfig>
remoteAddressSupplier
- A supplier of the address to connect to.ClientTransport
public HttpClient.RequestSender request(HttpMethod method)
HttpClient
.method
- the HTTP method to sendHttpClient.RequestSender
ready to finalize request and consume for responsepublic final HttpClient responseTimeout(@Nullable Duration maxReadOperationInterval)
ReadTimeoutHandler
is added to the channel
pipeline after sending the request and is removed when the response is fully received.
If the maxReadOperationInterval
is null
, any previous setting will be removed and no
maxReadOperationInterval
will be applied.
If the maxReadOperationInterval
is less than 1ms
, then 1ms
will be the
maxReadOperationInterval
.
The maxReadOperationInterval
setting on HttpClientRequest
level overrides any
maxReadOperationInterval
setting on HttpClient
level.maxReadOperationInterval
- the maximum duration allowed between each network-level read operations
(resolution: ms).HttpClient
ReadTimeoutHandler
public final HttpClient secure()
By default SslContext
is initialized with:
10
seconds handshake timeout unless
the environment property reactor.netty.tcp.sslHandshakeTimeout
is setHttpClient
public final HttpClient secure(Consumer<? super SslProvider.SslContextSpec> sslProviderBuilder)
The builder will produce the SslContext
with:
10
seconds handshake timeout unless the passed builder sets another configuration or
the environment property reactor.netty.tcp.sslHandshakeTimeout
is setsslProviderBuilder
- builder callback for further customization of SslContext.HttpClient
public HttpClient secure(SslProvider sslProvider)
SslProvider
.
Note: Hostname verification is not enabled by default.
If hostname verification is needed, please apply the
HttpClientSecurityUtils.HOSTNAME_VERIFICATION_CONFIGURER
configuration to the SslProvider
:
SslProvider.builder()
.sslContext(...)
.handlerConfigurator(HttpClientSecurityUtils.HOSTNAME_VERIFICATION_CONFIGURER)
.build();
sslProvider
- The provider to set when configuring SSLHttpClient
@Deprecated public final HttpClient tcpConfiguration(Function<? super TcpClient,? extends TcpClient> tcpMapper)
HttpClient
to achieve the same configurations.
This method will be removed in version 1.1.0.TcpClient
mapping function to update TCP configuration and
return an enriched HttpClient
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)
tcpMapper
- A TcpClient
mapping function to update TCP configuration and
return an enriched HttpClient
to use.HttpClient
public Mono<Void> warmup()
Mono
that triggers:
first request
absorbs the extra time needed to load resources.warmup
in class ClientTransport<HttpClient,HttpClientConfig>
Mono
representing the completion of the warmuppublic final HttpClient.WebsocketSender websocket()
HttpClient
.HttpClient.WebsocketSender
ready to consume for responsepublic final HttpClient.WebsocketSender websocket(WebsocketClientSpec websocketClientSpec)
HttpClient
.websocketClientSpec
- WebsocketClientSpec
for websocket configurationHttpClient.WebsocketSender
ready to consume for responsepublic final HttpClient wiretap(boolean enable)
Transport
Transport
category (logger),
DEBUG
logger level and AdvancedByteBufFormat.HEX_DUMP
for ByteBuf
format,
which means both events and content will be logged and the content will be in hex format.wiretap
in class Transport<HttpClient,HttpClientConfig>
enable
- specifies whether the wire logger configuration will be added to the pipelineTransport
reference