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 interfaceMarker interface for use withHttpClient.RequestSender.send(BiFunction).static interfaceAllow a request body configuration before calling one of the terminal,Publisherbased,HttpClient.ResponseReceiverAPI.static interfaceHttpClient.ResponseReceiver<S extends HttpClient.ResponseReceiver<?>>A response extractor for this configuredHttpClient.static interfaceHttpClient.UriConfiguration<S extends HttpClient.UriConfiguration<?>>A URI configuration.static interfaceAllow a websocket handling.static interfaceAllow a request body configuration before calling one of the terminal,Publisherbased,HttpClient.WebsocketReceiverAPI.Nested classes/interfaces inherited from class reactor.netty.transport.ClientTransport
ClientTransport.ResolvedAddressSelector<CONF> -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfinal HttpClientConfigure URI to use for this request/response.final HttpClientcompress(boolean compressionEnabled) Specifies whether compression (gzip, Brotli, and zstd) is enabled.final HttpClientApply cookies configuration.final HttpClientDeprecated.as of 1.1.0.final HttpClientcookieCodec(ClientCookieEncoder encoder) Deprecated.as of 1.1.0.final HttpClientcookieCodec(ClientCookieEncoder encoder, ClientCookieDecoder decoder) Deprecated.as of 1.1.0.final HttpClientApply cookies configuration emitted by the returned Mono before requesting.static HttpClientcreate()Prepare a pooledHttpClient.static HttpClientcreate(ConnectionProvider connectionProvider) Prepare anHttpClient.final HttpClient.RequestSenderdelete()HTTP DELETE to connect theHttpClient.final HttpClientdisableRetry(boolean disableRetry) Option to disableretry oncesupport for the outgoing requests that fail withAbortedException.isConnectionReset(Throwable).final HttpClientdoAfterRequest(BiConsumer<? super HttpClientRequest, ? super Connection> doAfterRequest) Setup a callback called whenHttpClientRequesthas been sent andHttpClientState.REQUEST_SENThas been emitted.final HttpClientdoAfterResponseSuccess(BiConsumer<? super HttpClientResponse, ? super Connection> doAfterResponseSuccess) Setup a callback called afterHttpClientResponsehas been fully received andHttpClientState.RESPONSE_COMPLETEDhas been emitted.final HttpClientdoOnError(BiConsumer<? super HttpClientRequest, ? super Throwable> doOnRequestError, BiConsumer<? super HttpClientResponse, ? super Throwable> doOnResponseError) Setup a callback called whenHttpClientRequesthas not been sent and whenHttpClientResponsehas not been fully received.final HttpClientdoOnRedirect(BiConsumer<? super HttpClientResponse, ? super Connection> doOnRedirect) Setup a callback called afterHttpClientResponseheaders have been received and the request is about to be redirected.final HttpClientdoOnRequest(BiConsumer<? super HttpClientRequest, ? super Connection> doOnRequest) Setup a callback called whenHttpClientRequestis about to be sent andHttpClientState.REQUEST_PREPAREDhas been emitted.final HttpClientdoOnRequestError(BiConsumer<? super HttpClientRequest, ? super Throwable> doOnRequestError) Setup a callback called whenHttpClientRequesthas not been sent.final HttpClientdoOnResponse(BiConsumer<? super HttpClientResponse, ? super Connection> doOnResponse) Setup a callback called afterHttpClientResponseheaders have been received andHttpClientState.RESPONSE_RECEIVEDhas been emitted.final HttpClientdoOnResponseError(BiConsumer<? super HttpClientResponse, ? super Throwable> doOnResponseError) Setup a callback called whenHttpClientResponsehas not been fully received,HttpClientState.RESPONSE_INCOMPLETEhas been emitted.final HttpClientfollowRedirect(boolean followRedirect) Specifies whether HTTP status 301|302|303|307|308 auto-redirect support is enabled.final HttpClientfollowRedirect(boolean followRedirect, @Nullable BiConsumer<HttpHeaders, HttpClientRequest> redirectRequestBiConsumer) Variant offollowRedirect(boolean)that also acceptsBiConsumerthat provides the headers from the previous request and the current redirect request.final HttpClientfollowRedirect(boolean followRedirect, @Nullable Consumer<HttpClientRequest> redirectRequestConsumer) Variant offollowRedirect(boolean)that also accepts a redirect request processor.final HttpClientfollowRedirect(BiPredicate<HttpClientRequest, HttpClientResponse> predicate) Enables auto-redirect support if the passedPredicatematches.final HttpClientfollowRedirect(BiPredicate<HttpClientRequest, HttpClientResponse> predicate, @Nullable BiConsumer<HttpHeaders, HttpClientRequest> redirectRequestBiConsumer) Variant offollowRedirect(BiPredicate)that also acceptsBiConsumerthat provides the headers from the previous request and the current redirect request.final HttpClientfollowRedirect(BiPredicate<HttpClientRequest, HttpClientResponse> predicate, @Nullable Consumer<HttpClientRequest> redirectRequestConsumer) Variant offollowRedirect(BiPredicate)that also accepts a redirect request processor.static HttpClientDeprecated.Use the other methods exposed byHttpClientto achieve the same configurations.final HttpClient.ResponseReceiver<?>get()HTTP GET to connect theHttpClient.final HttpClient.ResponseReceiver<?>head()HTTP HEAD to connect theHttpClient.final HttpClientheaders(Consumer<? super HttpHeaders> headerBuilder) Apply headers configuration.final HttpClientheadersWhen(Function<? super HttpHeaders, Mono<? extends HttpHeaders>> headerBuilder) Apply headers configuration emitted by the returned Mono before requesting.final HttpClienthttp2Settings(Consumer<Http2SettingsSpec.Builder> http2Settings) Apply HTTP/2 configuration.final HttpClienthttp3Settings(Consumer<Http3SettingsSpec.Builder> http3Settings) Apply HTTP/3 configuration.final HttpClienthttpMessageLogFactory(HttpMessageLogFactory httpMessageLogFactory) WhenHttpMessageis about to be logged the configured factory will be used for generating a sanitized log message.final HttpClienthttpResponseDecoder(Function<HttpResponseDecoderSpec, HttpResponseDecoderSpec> responseDecoderOptions) Configure theHttpClientCodec's response decoding options.final HttpClientkeepAlive(boolean keepAlive) Enable or Disable Keep-Alive support for the outgoing request.final HttpClientmapConnect(Function<? super Mono<? extends Connection>, ? extends Mono<? extends Connection>> connector) Intercept the connection lifecycle and allows delaying, transform or inject a context.final HttpClientWhether to enable metrics to be collected and registered in Micrometer'sglobalRegistryunder the nameMetrics.HTTP_CLIENT_PREFIX.final HttpClientmetrics(boolean enable, Supplier<? extends ChannelMetricsRecorder> recorder) Specifies whether the metrics are enabled on theTransport.final HttpClientmetrics(boolean enable, Supplier<? extends ChannelMetricsRecorder> recorder, Function<String, String> uriValue) Specifies whether the metrics are enabled on theHttpClient.static HttpClientPrepare an unpooledHttpClient.final HttpClientnoSSL()Removes any previously applied SSL configuration customization.final HttpClientobserve(ConnectionObserver observer) Set or add the givenConnectionObserverto observe the connection state changes.final HttpClient.ResponseReceiver<?>options()HTTP OPTIONS to connect theHttpClient.final HttpClient.RequestSenderpatch()HTTP PATCH to connect theHttpClient.final HttpClientport(int port) The port to which this client should connect.final HttpClient.RequestSenderpost()HTTP POST to connect theHttpClient.final HttpClientprotocol(HttpProtocol... supportedProtocols) The HTTP protocol to support.final HttpClientproxyWhen(BiFunction<HttpClientConfig, ? super ProxyProvider.TypeSpec, Mono<? extends ProxyProvider.Builder>> proxyBuilder) Supports proxy configuration with a deferred approach.final HttpClient.RequestSenderput()HTTP PUT to connect theHttpClient.final HttpClientremoteAddress(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 HttpClientresponseTimeout(@Nullable Duration maxReadOperationInterval) Specifies the maximum duration allowed between each network-level read operation while reading a given response (resolution: ms).final HttpClientsecure()Enable default sslContext support.final HttpClientsecure(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 HttpClienttcpConfiguration(Function<? super TcpClient, ? extends TcpClient> tcpMapper) Deprecated.Use the other methods exposed byHttpClientto achieve the same configurations.warmup()Based on the actual configuration, returns aMonothat 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 requestabsorbs the extra time needed to load resources.HTTP Websocket to connect theHttpClient.websocket(WebsocketClientSpec websocketClientSpec) HTTP Websocket to connect theHttpClient.final HttpClientwiretap(boolean enable) Apply or remove a wire logger configuration usingTransportcategory (logger),DEBUGlogger level andAdvancedByteBufFormat.HEX_DUMPforByteBufformat, 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, runOnMethods 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- theConnectionProviderto be used- Returns:
- a
HttpClient
-
from
Deprecated.Use the other methods exposed byHttpClientto achieve the same configurations. This method will be removed in version 1.1.0.Prepare anHttpClientNote: 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 loggingConfiguration via the other methods exposed by
HttpClientHttpClient.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 loggingWire 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
baseUrlonly 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 headerConsumerto 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,ClientCookieDecoderwill 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 theClientCookieEncoderandClientCookieDecoder.- 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 cookiesFunctionto invoke before sending- Returns:
- a new
HttpClient
-
delete
HTTP DELETE to connect theHttpClient.- Returns:
- a
HttpClient.RequestSenderready to prepare the content for response
-
disableRetry
Option to disableretry oncesupport for the outgoing requests that fail withAbortedException.isConnectionReset(Throwable).By default this is set to false in which case
retry onceis 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 whenHttpClientRequesthas been sent andHttpClientState.REQUEST_SENThas been emitted.- Parameters:
doAfterRequest- a callback called whenHttpClientRequesthas been sent- Returns:
- a new
HttpClient
-
doAfterResponseSuccess
public final HttpClient doAfterResponseSuccess(BiConsumer<? super HttpClientResponse, ? super Connection> doAfterResponseSuccess) Setup a callback called afterHttpClientResponsehas been fully received andHttpClientState.RESPONSE_COMPLETEDhas been emitted.- Parameters:
doAfterResponseSuccess- a callback called afterHttpClientResponsehas been fully received andHttpClientState.RESPONSE_COMPLETEDhas 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 whenHttpClientRequesthas not been sent and whenHttpClientResponsehas not been fully received.Note that some mutation of
HttpClientRequestperformed 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 afterHttpClientResponseheaders 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 afterHttpClientResponseheaders 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 whenHttpClientRequestis about to be sent andHttpClientState.REQUEST_PREPAREDhas been emitted.- Parameters:
doOnRequest- a callback called whenHttpClientRequestis about to be sent- Returns:
- a new
HttpClient
-
doOnRequestError
public final HttpClient doOnRequestError(BiConsumer<? super HttpClientRequest, ? super Throwable> doOnRequestError) Setup a callback called whenHttpClientRequesthas not been sent. Note that some mutation ofHttpClientRequestperformed 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 afterHttpClientResponseheaders have been received andHttpClientState.RESPONSE_RECEIVEDhas been emitted.- Parameters:
doOnResponse- a callback called afterHttpClientResponseheaders have been received- Returns:
- a new
HttpClient
-
doOnResponseError
public final HttpClient doOnResponseError(BiConsumer<? super HttpClientResponse, ? super Throwable> doOnResponseError) Setup a callback called whenHttpClientResponsehas not been fully received,HttpClientState.RESPONSE_INCOMPLETEhas been emitted.- Parameters:
doOnResponseError- a consumer observing response failures- Returns:
- a new
HttpClient
-
followRedirect
Enables auto-redirect support if the passedPredicatematches.Note: The passed
HttpClientRequestandHttpClientResponseshould be considered read-only and the implement SHOULD NOT consume or write the request/response in this predicate.Note: The sensitive headers
followRedirectare 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 acceptsBiConsumerthat 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. TheBiConsumerprovides 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
followRedirectare 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 acceptsBiConsumerthat 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. TheBiConsumerprovides 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.RequestSenderready to consume for response
-
head
HTTP HEAD to connect theHttpClient.- Returns:
- a
HttpClient.RequestSenderready to consume for response
-
headers
Apply headers configuration.- Parameters:
headerBuilder- the headerConsumerto 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 headerFunctionto invoke before sending- Returns:
- a new
HttpClient
-
http2Settings
Apply HTTP/2 configuration.- Parameters:
http2Settings- configuresHttp2SettingsSpecbefore requesting- Returns:
- a new
HttpClient
-
http3Settings
Apply HTTP/3 configuration.- Parameters:
http3Settings- configuresHttp3SettingsSpecbefore requesting- Returns:
- a new
HttpClient - Since:
- 1.2.0
-
httpMessageLogFactory
WhenHttpMessageis 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
DecoderExceptionmessage 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'sglobalRegistryunder the nameMetrics.HTTP_CLIENT_PREFIX.uriTagValuefunction receives the actual uri and returns the uri tag value that will be used for the metrics withMetrics.URItag. 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.URItag- Returns:
- a new
HttpClient - Since:
- 0.9.7
-
metrics
public final HttpClient metrics(boolean enable, Supplier<? extends ChannelMetricsRecorder> recorder) Description copied from class:TransportSpecifies 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:
metricsin classTransport<HttpClient,HttpClientConfig> - Parameters:
enable- if true enables the metrics on theTransport.recorder- a supplier for theChannelMetricsRecorder- Returns:
- a new
Transportreference
-
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).uriValuefunction 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:TransportSet or add the givenConnectionObserverto observe the connection state changes.- Overrides:
observein classTransport<HttpClient,HttpClientConfig> - Parameters:
observer- theConnectionObserverto be set or add- Returns:
- a new
Transportreference
-
options
HTTP OPTIONS to connect theHttpClient.- Returns:
- a
HttpClient.RequestSenderready to consume for response
-
patch
HTTP PATCH to connect theHttpClient.- Returns:
- a
HttpClient.RequestSenderready to finalize request and consume for response
-
port
The port to which this client should connect. If a port is not specified, the default port80is used.Note: The port can be specified also with
PORTenvironment variable.- Overrides:
portin classClientTransport<HttpClient,HttpClientConfig> - Parameters:
port- the port to connect to- Returns:
- a new
HttpClient
-
post
HTTP POST to connect theHttpClient.- Returns:
- a
HttpClient.RequestSenderready to finalize request and consume for response
-
protocol
The HTTP protocol to support. Default isHttpProtocol.HTTP11.- Parameters:
supportedProtocols- The variousHttpProtocolthis client will support- Returns:
- a new
HttpClient
-
put
HTTP PUT to connect theHttpClient.- Returns:
- a
HttpClient.RequestSenderready to finalize request and consume for response
-
remoteAddress
Description copied from class:ClientTransportThe address to which this client should connect on each subscribe.- Overrides:
remoteAddressin 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.RequestSenderready 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,ReadTimeoutHandleris added to the channel pipeline after sending the request and is removed when the response is fully received. If themaxReadOperationIntervalisnull, any previous setting will be removed and nomaxReadOperationIntervalwill be applied. If themaxReadOperationIntervalis less than1ms, then1mswill be themaxReadOperationInterval. ThemaxReadOperationIntervalsetting onHttpClientRequestlevel overrides anymaxReadOperationIntervalsetting onHttpClientlevel.- 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
SslContextis initialized with:10seconds handshake timeout unless the environment propertyreactor.netty.tcp.sslHandshakeTimeoutis set3seconds close_notify flush timeout0second 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
SslContextwith:10seconds handshake timeout unless the passed builder sets another configuration or the environment propertyreactor.netty.tcp.sslHandshakeTimeoutis set3seconds close_notify flush timeout0second 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_CONFIGURERconfiguration 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 byHttpClientto achieve the same configurations. This method will be removed in version 1.1.0.Apply aTcpClientmapping function to update TCP configuration and return an enrichedHttpClientto 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 loggingConfiguration via the other methods exposed by
HttpClientHttpClient.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 loggingWire logging in plain text
HttpClient.wiretap("logger", LogLevel.DEBUG, AdvancedByteBufFormat.TEXTUAL)- Parameters:
tcpMapper- ATcpClientmapping function to update TCP configuration and return an enrichedHttpClientto use.- Returns:
- a new
HttpClient
-
warmup
Based on the actual configuration, returns aMonothat 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 requestabsorbs the extra time needed to load resources.- Overrides:
warmupin classClientTransport<HttpClient,HttpClientConfig> - Returns:
- a
Monorepresenting 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
HttpClientreference - Since:
- 1.2.3
-
websocket
HTTP Websocket to connect theHttpClient.- Returns:
- a
HttpClient.WebsocketSenderready to consume for response
-
websocket
HTTP Websocket to connect theHttpClient.- Parameters:
websocketClientSpec-WebsocketClientSpecfor websocket configuration- Returns:
- a
HttpClient.WebsocketSenderready to consume for response - Since:
- 0.9.7
-
wiretap
Description copied from class:TransportApply or remove a wire logger configuration usingTransportcategory (logger),DEBUGlogger level andAdvancedByteBufFormat.HEX_DUMPforByteBufformat, which means both events and content will be logged and the content will be in hex format.- Overrides:
wiretapin classTransport<HttpClient,HttpClientConfig> - Parameters:
enable- specifies whether the wire logger configuration will be added to the pipeline- Returns:
- a new
Transportreference
-