public abstract class HttpClient extends Object
TcpClient.connect()
is ultimately called.
Internally, materialization happens in three phases, first tcpConfiguration()
is called to retrieve a ready to use TcpClient
, then TcpClient.configure()
retrieve a usable Bootstrap
for the final TcpClient.connect()
is 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 |
addressSupplier(java.util.function.Supplier<? extends SocketAddress> connectAddressSupplier)
Deprecated.
as of 0.9.7. Use
remoteAddress(Supplier) |
HttpClient |
baseUrl(String baseUrl)
Configure URI to use for this request/response.
|
HttpClient |
compress(boolean compressionEnabled)
Specifies whether GZip compression/websocket compression
extension is enabled.
|
HttpClient |
cookie(Cookie cookie)
Apply cookies configuration.
|
HttpClient |
cookie(String name,
java.util.function.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,
java.util.function.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(java.util.function.BiConsumer<? super HttpClientRequest,? super Connection> doAfterRequest)
Setup a callback called when
HttpClientRequest has been sent
and HttpClientState.REQUEST_SENT has been emitted. |
HttpClient |
doAfterResponse(java.util.function.BiConsumer<? super HttpClientResponse,? super Connection> doAfterResponse)
Deprecated.
as of 0.9.5. Consider using
doAfterResponseSuccess(BiConsumer) or
doOnResponseError(BiConsumer) |
HttpClient |
doAfterResponseSuccess(java.util.function.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(java.util.function.BiConsumer<? super HttpClientRequest,? super Throwable> doOnRequest,
java.util.function.BiConsumer<? super HttpClientResponse,? super Throwable> doOnResponse)
Setup a callback called when
HttpClientRequest has not been sent and when HttpClientResponse has not been fully
received. |
HttpClient |
doOnRedirect(java.util.function.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(java.util.function.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(java.util.function.BiConsumer<? super HttpClientRequest,? super Throwable> doOnRequest)
Setup a callback called when
HttpClientRequest has not been sent. |
HttpClient |
doOnResponse(java.util.function.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(java.util.function.BiConsumer<? super HttpClientResponse,? super Throwable> doOnResponse)
Setup a callback called when
HttpClientResponse has not been fully
received, HttpClientState.RESPONSE_INCOMPLETE has been emitted. |
HttpClient |
followRedirect(java.util.function.BiPredicate<HttpClientRequest,HttpClientResponse> predicate)
Enables auto-redirect support if the passed
Predicate matches. |
HttpClient |
followRedirect(java.util.function.BiPredicate<HttpClientRequest,HttpClientResponse> predicate,
java.util.function.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(java.util.function.BiPredicate<HttpClientRequest,HttpClientResponse> predicate,
java.util.function.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,
java.util.function.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,
java.util.function.Consumer<HttpClientRequest> redirectRequestConsumer)
Variant of
followRedirect(boolean) that also accepts a redirect request
processor. |
static HttpClient |
from(TcpClient tcpClient)
Prepare a pooled
HttpClient |
HttpClient.ResponseReceiver<?> |
get()
HTTP GET to connect the
HttpClient . |
HttpClient.ResponseReceiver<?> |
head()
HTTP HEAD to connect the
HttpClient . |
HttpClient |
headers(java.util.function.Consumer<? super HttpHeaders> headerBuilder)
Apply headers configuration.
|
HttpClient |
headersWhen(java.util.function.Function<? super HttpHeaders,Mono<? extends HttpHeaders>> headerBuilder)
Apply headers configuration emitted by the returned Mono before requesting.
|
HttpClient |
httpResponseDecoder(java.util.function.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(java.util.function.BiFunction<? super Mono<? extends Connection>,? super Bootstrap,? extends Mono<? extends Connection>> connector)
Intercept the connection lifecycle and allows to delay, transform or inject a
context.
|
HttpClient |
metrics(boolean metricsEnabled)
Deprecated.
as of 0.9.7. Use
metrics(boolean, Function) |
HttpClient |
metrics(boolean metricsEnabled,
java.util.function.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 metricsEnabled,
HttpClientMetricsRecorder recorder)
Deprecated.
as of 0.9.7. Use
metrics(boolean, Supplier) |
HttpClient |
metrics(boolean metricsEnabled,
java.util.function.Supplier<? extends HttpClientMetricsRecorder> recorder)
Specifies whether the metrics are enabled on the
HttpClient . |
HttpClient |
metrics(boolean metricsEnabled,
java.util.function.Supplier<? extends HttpClientMetricsRecorder> recorder,
java.util.function.Function<String,String> uriValue)
Specifies whether the metrics are enabled on the
HttpClient . |
static HttpClient |
newConnection()
Prepare an unpooled
HttpClient . |
HttpClient |
observe(ConnectionObserver observer)
Setup all lifecycle callbacks called on or after
Channel
has been connected and after it has been disconnected. |
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(java.util.function.Supplier<? extends SocketAddress> remoteAddressSupplier)
The address to which this client should connect for each subscribe.
|
HttpClient.RequestSender |
request(HttpMethod method)
Use the passed HTTP method to connect the
HttpClient . |
HttpClient |
responseTimeout(java.time.Duration timeout)
Specifies the response timeout duration in milliseconds.
|
HttpClient |
secure()
Enable default sslContext support.
|
HttpClient |
secure(java.util.function.Consumer<? super SslProvider.SslContextSpec> sslProviderBuilder)
Apply an SSL configuration customization via the passed builder.
|
protected TcpClient |
tcpConfiguration()
Get a TcpClient from the parent
HttpClient chain to use with TcpClient.connect() } or separately |
HttpClient |
tcpConfiguration(java.util.function.Function<? super TcpClient,? extends TcpClient> tcpMapper)
Apply
Bootstrap configuration given mapper taking currently configured one
and returning a new one to be ultimately used for socket binding. |
HttpClient.WebsocketSender |
websocket()
HTTP Websocket to connect the
HttpClient . |
HttpClient.WebsocketSender |
websocket(boolean proxyPing)
Deprecated.
as of 0.9.7. Use
websocket(WebsocketClientSpec) |
HttpClient.WebsocketSender |
websocket(int maxFramePayloadLength)
Deprecated.
as of 0.9.7. Use
websocket(WebsocketClientSpec) |
HttpClient.WebsocketSender |
websocket(String subprotocols)
Deprecated.
as of 0.9.7. Use
websocket(WebsocketClientSpec) |
HttpClient.WebsocketSender |
websocket(String subprotocols,
int maxFramePayloadLength)
Deprecated.
as of 0.9.7. Use
websocket(WebsocketClientSpec) |
HttpClient.WebsocketSender |
websocket(String subprotocols,
int maxFramePayloadLength,
boolean handlePing)
Deprecated.
as of 0.9.7. Use
websocket(WebsocketClientSpec) |
HttpClient.WebsocketSender |
websocket(WebsocketClientSpec websocketClientSpec)
HTTP Websocket to connect the
HttpClient . |
HttpClient |
wiretap(boolean enable)
Apply or remove a wire logger configuration using
HttpClient category
and DEBUG logger level |
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.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 static HttpClient from(TcpClient tcpClient)
HttpClient
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.@Deprecated public final HttpClient addressSupplier(java.util.function.Supplier<? extends SocketAddress> connectAddressSupplier)
remoteAddress(Supplier)
connectAddressSupplier
- A supplier of the address to connect to.HttpClient
public final HttpClient remoteAddress(java.util.function.Supplier<? extends SocketAddress> remoteAddressSupplier)
remoteAddressSupplier
- A supplier of the address to connect to.HttpClient
public final HttpClient compress(boolean compressionEnabled)
Note: Using this method for enabling websocket compression is strongly discouraged.
As of 0.9.7, use WebsocketClientSpec.builder()
for providing websocket compression configuration.
In 0.9.x enabling compression for HTTP, implicitly enables the compression also for Websocket.
In 1.0.x this behaviour will be changed and this method will enable the compression only for HTTP.
Using WebsocketClientSpec.builder()
, one will be able explicitly to enable the compression for Websocket.
compressionEnabled
- if true GZip compression/websocket compression extension
is enabled otherwise disabled (default: false)HttpClient
public final HttpClient mapConnect(java.util.function.BiFunction<? super Mono<? extends Connection>,? super Bootstrap,? extends Mono<? extends Connection>> connector)
connector
- A bi function mapping the default connection and configured
bootstrap to a target connection.HttpClient
public final HttpClient cookie(Cookie cookie)
cookie
- a cookie to append to the request(s)HttpClient
public final HttpClient cookie(String name, java.util.function.Consumer<? super Cookie> cookieBuilder)
cookieBuilder
- the header Consumer
to invoke before requestingHttpClient
public final HttpClient cookiesWhen(String name, java.util.function.Function<? super Cookie,Mono<? extends Cookie>> cookieBuilder)
cookieBuilder
- the cookies Function
to invoke before sendingHttpClient
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.RequestSender delete()
HttpClient
.HttpClient.RequestSender
ready to prepare the content for responsepublic final HttpClient doOnError(java.util.function.BiConsumer<? super HttpClientRequest,? super Throwable> doOnRequest, java.util.function.BiConsumer<? super HttpClientResponse,? super Throwable> doOnResponse)
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.
doOnRequest
- a consumer observing request failuresdoOnResponse
- a consumer observing response failuresHttpClient
public final HttpClient doOnRequest(java.util.function.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(java.util.function.BiConsumer<? super HttpClientRequest,? super Throwable> doOnRequest)
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.doOnRequest
- a consumer observing request failuresHttpClient
public final HttpClient doAfterRequest(java.util.function.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 doOnResponse(java.util.function.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 doOnRedirect(java.util.function.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 doOnResponseError(java.util.function.BiConsumer<? super HttpClientResponse,? super Throwable> doOnResponse)
HttpClientResponse
has not been fully
received, HttpClientState.RESPONSE_INCOMPLETE
has been emitted.doOnResponse
- a consumer observing response failuresHttpClient
@Deprecated public final HttpClient doAfterResponse(java.util.function.BiConsumer<? super HttpClientResponse,? super Connection> doAfterResponse)
doAfterResponseSuccess(BiConsumer)
or
doOnResponseError(BiConsumer)
HttpClientState.RESPONSE_RECEIVED
has been emitted and the connection is
returned to the pool or closed. The callback is invoked in both cases when the
response is successful/there are errors.doAfterResponse
- a callback called after
HttpClientState.RESPONSE_RECEIVED
has been emitted and the connection is
returned to the pool or closed. The callback is invoked in both cases when the
response is successful/there are errors.HttpClient
public final HttpClient doAfterResponseSuccess(java.util.function.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.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(java.util.function.Consumer<? super HttpHeaders> headerBuilder)
headerBuilder
- the header Consumer
to invoke before requestingHttpClient
public final HttpClient headersWhen(java.util.function.Function<? super HttpHeaders,Mono<? extends HttpHeaders>> headerBuilder)
headerBuilder
- the header Function
to invoke before sendingHttpClient
public final HttpClient keepAlive(boolean keepAlive)
keepAlive
- true if keepAlive should be enabled (default: true)HttpClient
public 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 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 java.util.function.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 java.util.function.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 followRedirect(java.util.function.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(java.util.function.BiPredicate<HttpClientRequest,HttpClientResponse> predicate, @Nullable java.util.function.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(java.util.function.BiPredicate<HttpClientRequest,HttpClientResponse> predicate, @Nullable java.util.function.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 observe(ConnectionObserver observer)
Channel
has been connected and after it has been disconnected.observer
- a consumer observing state changesHttpClient
public 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)
port
- The port to connect to.HttpClient
public 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 server will supportHttpClient
public final HttpClient.RequestSender put()
HttpClient
.HttpClient.RequestSender
ready to finalize request and consume for responsepublic HttpClient.RequestSender request(HttpMethod method)
HttpClient
.method
- the HTTP method to sendHttpClient.RequestSender
ready to finalize request and consume for responsepublic final HttpClient responseTimeout(java.time.Duration timeout)
timeout
is null
, any previous setting will be removed and no response timeout
will be applied.
If the timeout
is less than 1ms
, then 1ms
will be the response timeout.
The response timeout setting on HttpClientRequest
level overrides any response timeout
setting on HttpClient
level.timeout
- the response timeout duration (resolution: ms)HttpClient
public final HttpClient secure()
SslContext
will be
assigned to
with a default value of 10
seconds handshake timeout unless
the environment property reactor.netty.tcp.sslHandshakeTimeout
is set.HttpClient
public final HttpClient secure(java.util.function.Consumer<? super SslProvider.SslContextSpec> sslProviderBuilder)
SslContext
to be passed to with a default value of
10
seconds handshake timeout unless the environment property reactor.netty.tcp.sslHandshakeTimeout
is set.sslProviderBuilder
- builder callback for further customization of SslContext.HttpClient
public final HttpClient tcpConfiguration(java.util.function.Function<? super TcpClient,? extends TcpClient> tcpMapper)
Bootstrap
configuration given mapper taking currently configured one
and returning a new one to be ultimately used for socket binding. Configuration
will apply during tcpConfiguration()
phase.
Always prefer secure()
to
tcpConfiguration()
and TcpClient.secure()
. While configuration
with the later is possible, secure()
will inject extra information
for HTTPS support.
tcpMapper
- A tcpClient mapping function to update tcp configuration and
return an enriched tcp client to use.HttpClient
public final HttpClient wiretap(boolean enable)
HttpClient
category
and DEBUG
logger levelenable
- Specifies whether the wire logger configuration will be added to
the pipelineHttpClient
@Deprecated public final HttpClient metrics(boolean metricsEnabled)
metrics(boolean, Function)
globalRegistry
under the name Metrics.HTTP_CLIENT_PREFIX
.
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.
metricsEnabled
- true enables metrics collection; false disables itHttpClient
public final HttpClient metrics(boolean metricsEnabled, @Nullable java.util.function.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.
metricsEnabled
- 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
@Deprecated public final HttpClient metrics(boolean metricsEnabled, HttpClientMetricsRecorder recorder)
metrics(boolean, Supplier)
HttpClient
.
All generated metrics are provided to the specified recorder.metricsEnabled
- if true enables the metrics on the server.recorder
- the HttpClientMetricsRecorder
HttpClient
public final HttpClient metrics(boolean metricsEnabled, java.util.function.Supplier<? extends HttpClientMetricsRecorder> recorder)
HttpClient
.
All generated metrics are provided to the specified recorder
which is only instantiated if metrics are being enabled.metricsEnabled
- if true enables the metrics on the server.recorder
- a supplier for the HttpClientMetricsRecorder
HttpClient
public final HttpClient metrics(boolean metricsEnabled, java.util.function.Supplier<? extends HttpClientMetricsRecorder> recorder, java.util.function.Function<String,String> uriValue)
HttpClient
.
All generated metrics are provided to the specified recorder
which is only instantiated if metrics are being enabled.
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.
metricsEnabled
- if true enables the metrics on the server.recorder
- a supplier for the HttpClientMetricsRecorder
uriValue
- 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 httpResponseDecoder(java.util.function.Function<HttpResponseDecoderSpec,HttpResponseDecoderSpec> responseDecoderOptions)
HttpClientCodec
's response decoding options.responseDecoderOptions
- a function to mutate the provided Http response decoder optionsHttpClient
public 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 response@Deprecated public final HttpClient.WebsocketSender websocket(String subprotocols)
websocket(WebsocketClientSpec)
HttpClient
.subprotocols
- a websocket subprotocol comma separated listHttpClient.WebsocketSender
ready to consume for response@Deprecated public final HttpClient.WebsocketSender websocket(int maxFramePayloadLength)
websocket(WebsocketClientSpec)
HttpClient
.maxFramePayloadLength
- maximum allowable frame payload lengthHttpClient.WebsocketSender
ready to consume for response@Deprecated public final HttpClient.WebsocketSender websocket(boolean proxyPing)
websocket(WebsocketClientSpec)
HttpClient
.proxyPing
- whether to proxy websocket ping frames or respond to themHttpClient.WebsocketSender
ready to consume for response@Deprecated public final HttpClient.WebsocketSender websocket(String subprotocols, int maxFramePayloadLength)
websocket(WebsocketClientSpec)
HttpClient
.subprotocols
- a websocket subprotocol comma separated listmaxFramePayloadLength
- maximum allowable frame payload lengthHttpClient.WebsocketSender
ready to consume for response@Deprecated public final HttpClient.WebsocketSender websocket(String subprotocols, int maxFramePayloadLength, boolean handlePing)
websocket(WebsocketClientSpec)
HttpClient
.subprotocols
- a websocket subprotocol comma separated listmaxFramePayloadLength
- maximum allowable frame payload lengthhandlePing
- whether to proxy websocket ping frames or respond to themHttpClient.WebsocketSender
ready to consume for responseprotected TcpClient tcpConfiguration()
HttpClient
chain to use with TcpClient.connect()
} or separatelyTcpClient