Top Description Inners Fields Constructors Methods
reactor.netty.http.client

public abstract Class HttpClient

extends ClientTransport<HttpClient, HttpClientConfig>
Class Inheritance
Known Direct Subclasses
reactor.netty.http.client.HttpClientConnect
Imports
java.net.SocketAddress, .URI, java.time.Duration, java.util.Objects, .Optional, java.util.function.BiConsumer, .BiFunction, .BiPredicate, .Consumer, .Function, .Supplier, io.netty.buffer.ByteBuf, io.netty.handler.codec.DecoderException, io.netty.handler.codec.http.HttpHeaderNames, .HttpHeaderValues, .HttpHeaders, .HttpMessage, .HttpMethod, .HttpUtil, .HttpVersion, io.netty.handler.codec.http.cookie.ClientCookieDecoder, .ClientCookieEncoder, .Cookie, .DefaultCookie, io.netty.handler.ssl.OpenSsl, .SslContext, org.reactivestreams.Publisher, .Subscriber, reactor.core.publisher.Flux, .Mono, reactor.netty.ByteBufFlux, .ByteBufMono, .Connection, .ConnectionObserver, .NettyOutbound, reactor.netty.channel.ChannelMetricsRecorder, reactor.netty.http.Http2SettingsSpec, .HttpProtocol, reactor.netty.http.logging.HttpMessageLogFactory, .ReactorNettyHttpMessageLogFactory, reactor.netty.http.websocket.WebsocketInbound, .WebsocketOutbound, reactor.netty.internal.util.Metrics, reactor.netty.resources.ConnectionProvider, reactor.netty.tcp.SslProvider, .TcpClient, reactor.netty.transport.ClientTransport, reactor.util.Logger, .Loggers, reactor.util.annotation.Nullable

An HttpClient allows building in a safe immutable way an http client that is materialized and connecting when HttpClient#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();

Authors
Stephane Maldini, Violeta Georgieva

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static interface
public static interface
HttpClient.RequestSender

Allow a request body configuration before calling one of the terminal, Publisher based, ResponseReceiver API.

public static interface
HttpClient.ResponseReceiver<S extends HttpClient.ResponseReceiver<?>>

A response extractor for this configured HttpClient.

public static interface
HttpClient.UriConfiguration<S extends HttpClient.UriConfiguration<?>>

A URI configuration.

public static interface
HttpClient.WebsocketReceiver<S extends HttpClient.WebsocketReceiver<?>>

Allow a websocket handling.

public static interface
HttpClient.WebsocketSender

Allow a request body configuration before calling one of the terminal, Publisher based, WebsocketReceiver API.

Field Summary

Modifier and TypeField and Description
pack-priv static final String
pack-priv static final String
pack-priv static final Logger
public static final String
pack-priv static final String
pack-priv static final String

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public final HttpClient

Returns:

the appropriate sending or receiving contract
baseUrl
(String
a default base url that can be fully sufficient for request or can be used to prepend future UriConfiguration#uri calls.
baseUrl
)

Configure URI to use for this request/response.

public final HttpClient

Returns:

a new HttpClient
compress
(boolean
if true GZip compression is enabled otherwise disabled (default: false)
compressionEnabled
)

Specifies whether GZip compression is enabled.

public final HttpClient

Returns:

a new HttpClient
cookieCodec
(ClientCookieEncoder
the preferred ClientCookieEncoder
encoder
)

Deprecated as of 1.1.0. This will be removed in 2.0.0 as Netty 5 supports only strict validation.
Configure the ClientCookieEncoder, ClientCookieDecoder will be chosen based on the encoder.
public final HttpClient

Returns:

a new HttpClient
cookieCodec
(ClientCookieEncoder
the preferred ClientCookieEncoder
encoder
,
ClientCookieDecoder
the preferred ClientCookieDecoder
decoder
)

Deprecated as of 1.1.0. This will be removed in 2.0.0 as Netty 5 supports only strict validation.
Configure the ClientCookieEncoder and ClientCookieDecoder.
public final HttpClient

Returns:

a new HttpClient
cookiesWhen
(String name, Function<? super Cookie, Mono<? extends Cookie>>
the cookies Function to invoke before sending
cookieBuilder
)

Apply cookies configuration emitted by the returned Mono before requesting.

public static HttpClient

Returns:

a HttpClient
create
()

Prepare a pooled HttpClient.

public static HttpClient

Returns:

a HttpClient
create
(ConnectionProvider
the ConnectionProvider to be used
connectionProvider
)

Prepare an HttpClient.

public final HttpClient.RequestSender

Returns:

a RequestSender ready to prepare the content for response
delete
()

HTTP DELETE to connect the HttpClient.

public final HttpClient

Returns:

a new HttpClient
disableRetry
(boolean
true to disable retry once, false to enable it
disableRetry
)

Option to disable retry once support for the outgoing requests that fail with reactor.netty.channel.AbortedException#isConnectionReset(Throwable).

public final HttpClient

Returns:

a new HttpClient
doAfterRequest
(BiConsumer<? super HttpClientRequest, ? super Connection>
a callback called when HttpClientRequest has been sent
doAfterRequest
)

Setup a callback called when HttpClientRequest has been sent and HttpClientState#REQUEST_SENT has been emitted.

public final HttpClient

Returns:

a new HttpClient
doAfterResponseSuccess
(BiConsumer<? super HttpClientResponse, ? super Connection>
a callback called after HttpClientResponse has been fully received and HttpClientState#RESPONSE_COMPLETED has been emitted.
doAfterResponseSuccess
)

Setup a callback called after HttpClientResponse has been fully received and HttpClientState#RESPONSE_COMPLETED has been emitted.

public final HttpClient

Returns:

a new HttpClient
doOnError
(BiConsumer<? super HttpClientRequest, ? super Throwable>
a consumer observing request failures
doOnRequestError
,
BiConsumer<? super HttpClientResponse, ? super Throwable>
a consumer observing response failures
doOnResponseError
)

Setup a callback called when HttpClientRequest has not been sent and when HttpClientResponse has not been fully received.

public final HttpClient

Returns:

a new HttpClient
doOnRedirect
(BiConsumer<? super HttpClientResponse, ? super Connection>
a callback called after HttpClientResponse headers have been received and the request is about to be redirected
doOnRedirect
)

Setup a callback called after HttpClientResponse headers have been received and the request is about to be redirected.

public final HttpClient

Returns:

a new HttpClient
doOnRequest
(BiConsumer<? super HttpClientRequest, ? super Connection>
a callback called when HttpClientRequest is about to be sent
doOnRequest
)

Setup a callback called when HttpClientRequest is about to be sent and HttpClientState#REQUEST_PREPARED has been emitted.

public final HttpClient

Returns:

a new HttpClient
doOnRequestError
(BiConsumer<? super HttpClientRequest, ? super Throwable>
a consumer observing request failures
doOnRequestError
)

Setup a callback called when HttpClientRequest has not been sent.

public final HttpClient

Returns:

a new HttpClient
doOnResponse
(BiConsumer<? super HttpClientResponse, ? super Connection>
a callback called after HttpClientResponse headers have been received
doOnResponse
)

Setup a callback called after HttpClientResponse headers have been received and HttpClientState#RESPONSE_RECEIVED has been emitted.

public final HttpClient

Returns:

a new HttpClient
doOnResponseError
(BiConsumer<? super HttpClientResponse, ? super Throwable>
a consumer observing response failures
doOnResponseError
)

Setup a callback called when HttpClientResponse has not been fully received, HttpClientState#RESPONSE_INCOMPLETE has been emitted.

public final HttpClient

Returns:

a new HttpClient
followRedirect
(BiPredicate<HttpClientRequest, HttpClientResponse>
that returns true to enable auto-redirect support.
predicate
)

Enables auto-redirect support if the passed java.util.function.Predicate matches.

public final HttpClient

Returns:

a new HttpClient
followRedirect
(BiPredicate<HttpClientRequest, HttpClientResponse>
that returns true to enable auto-redirect support.
predicate
,
BiConsumer<HttpHeaders, HttpClientRequest>
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 HttpClientRequest#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.
redirectRequestBiConsumer
)

Variant of followRedirect(BiPredicate) that also accepts BiConsumer that provides the headers from the previous request and the current redirect request.

public final HttpClient

Returns:

a new HttpClient
followRedirect
(BiPredicate<HttpClientRequest, HttpClientResponse>
that returns true to enable auto-redirect support.
predicate
,
Consumer<HttpClientRequest>
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 HttpClientRequest#redirectedFrom() to check the original and any number of subsequent redirect(s), including the one that is in progress.
redirectRequestConsumer
)

Variant of followRedirect(BiPredicate) that also accepts a redirect request processor.

public final HttpClient

Returns:

a new HttpClient
followRedirect
(boolean
if true HTTP status 301|302|307|308 auto-redirect support is enabled, otherwise disabled (default: false).
followRedirect
)

Specifies whether HTTP status 301|302|303|307|308 auto-redirect support is enabled.

public final HttpClient

Returns:

a new HttpClient
followRedirect
(boolean
if true HTTP status 301|302|307|308 auto-redirect support is enabled, otherwise disabled (default: false).
followRedirect
,
BiConsumer<HttpHeaders, HttpClientRequest>
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 HttpClientRequest#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.
redirectRequestBiConsumer
)

Variant of followRedirect(boolean) that also accepts BiConsumer that provides the headers from the previous request and the current redirect request.

public final HttpClient

Returns:

a new HttpClient
followRedirect
(boolean
if true HTTP status 301|302|307|308 auto-redirect support is enabled, otherwise disabled (default: false).
followRedirect
,
Consumer<HttpClientRequest>
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 HttpClientRequest#redirectedFrom() to check the original and any number of subsequent redirect(s), including the one that is in progress.
redirectRequestConsumer
)

Variant of followRedirect(boolean) that also accepts a redirect request processor.

public static HttpClient

Returns:

a new 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.
Prepare an HttpClient

Note

There isn't only one method that replaces this deprecated method.

public final HttpClient.ResponseReceiver<?>

Returns:

a RequestSender ready to consume for response
get
()

HTTP GET to connect the HttpClient.

public final HttpClient.ResponseReceiver<?>

Returns:

a RequestSender ready to consume for response
head
()

HTTP HEAD to connect the HttpClient.

public final HttpClient

Returns:

a new HttpClient
headers
(Consumer<? super HttpHeaders>
the header Consumer to invoke before requesting
headerBuilder
)

Apply headers configuration.

public final HttpClient

Returns:

a new HttpClient
headersWhen
(Function<? super HttpHeaders, Mono<? extends HttpHeaders>>
the header Function to invoke before sending
headerBuilder
)

Apply headers configuration emitted by the returned Mono before requesting.

public final HttpClient

Returns:

a new HttpClient
http2Settings
(Consumer<Http2SettingsSpec.Builder>
configures Http2SettingsSpec before requesting
http2Settings
)

Apply HTTP/2 configuration.

public final HttpClient

Returns:

a new HttpClient
httpMessageLogFactory
(HttpMessageLogFactory
the factory for generating the log message
httpMessageLogFactory
)

When HttpMessage is about to be logged the configured factory will be used for generating a sanitized log message.

public final HttpClient

Returns:

a new HttpClient
httpResponseDecoder
(Function<HttpResponseDecoderSpec, HttpResponseDecoderSpec>
a function to mutate the provided Http response decoder options
responseDecoderOptions
)

Configure the io.netty.handler.codec.http.HttpClientCodec's response decoding options.

pack-priv static boolean
public final HttpClient

Returns:

a new HttpClient
keepAlive
(boolean
true if keepAlive should be enabled (default: true)
keepAlive
)

Enable or Disable Keep-Alive support for the outgoing request.

public final HttpClient

Returns:

a new HttpClient
mapConnect
(Function<? super Mono<? extends Connection>, ? extends Mono<? extends Connection>>
A bi function mapping the default connection and configured bootstrap to a target connection.
connector
)

Intercept the connection lifecycle and allows delaying, transform or inject a context.

public final HttpClient

Returns:

a new HttpClient
metrics
(boolean
true enables metrics collection; false disables it
enable
,
Function<String, String>
a function that receives the actual uri and returns the uri tag value that will be used for the metrics with reactor.netty.Metrics#URI tag
uriTagValue
)

Whether to enable metrics to be collected and registered in Micrometer's globalRegistry under the name reactor.netty.Metrics#HTTP_CLIENT_PREFIX.

public final HttpClient
metrics(boolean
if true enables the metrics on the Transport.
enable
,
Supplier<? extends ChannelMetricsRecorder>
a supplier for the ChannelMetricsRecorder
recorder
)

Overrides reactor.netty.transport.Transport.metrics.

Specifies whether the metrics are enabled on the Transport.
public final HttpClient

Returns:

a new HttpClient
metrics
(boolean
true enables metrics collection; false disables it
enable
,
Supplier<? extends ChannelMetricsRecorder>
a supplier for the metrics recorder that receives the collected metrics
recorder
,
Function<String, String>
a function that receives the actual uri and returns the uri value that will be used when the metrics are propagated to the recorder.
uriValue
)

Specifies whether the metrics are enabled on the HttpClient.

public static HttpClient

Returns:

a HttpClient
newConnection
()

Prepare an unpooled HttpClient.

public final HttpClient

Returns:

a new HttpClient
noSSL
()

Removes any previously applied SSL configuration customization.

public final HttpClient
observe(ConnectionObserver
the ConnectionObserver to be set or add
observer
)

Overrides reactor.netty.transport.Transport.observe.

Set or add the given ConnectionObserver to observe the connection state changes.
public final HttpClient.ResponseReceiver<?>

Returns:

a RequestSender ready to consume for response
options
()

HTTP OPTIONS to connect the HttpClient.

public final HttpClient.RequestSender

Returns:

a RequestSender ready to finalize request and consume for response
patch
()

HTTP PATCH to connect the HttpClient.

public final HttpClient
port(int
the port to connect to
port
)

Overrides reactor.netty.transport.ClientTransport.port.

The port to which this client should connect.
public final HttpClient.RequestSender

Returns:

a RequestSender ready to finalize request and consume for response
post
()

HTTP POST to connect the HttpClient.

public final HttpClient

Returns:

a new HttpClient
protocol
(HttpProtocol...
The various HttpProtocol this client will support
supportedProtocols
)

The HTTP protocol to support.

public final HttpClient.RequestSender

Returns:

a RequestSender ready to finalize request and consume for response
put
()

HTTP PUT to connect the HttpClient.

pack-priv static String
public final HttpClient
remoteAddress(Supplier<? extends SocketAddress>
A supplier of the address to connect to.
remoteAddressSupplier
)

Overrides reactor.netty.transport.ClientTransport.remoteAddress.

The address to which this client should connect on each subscribe.
public HttpClient.RequestSender

Returns:

a RequestSender ready to finalize request and consume for response
request
(HttpMethod
the HTTP method to send
method
)

Use the passed HTTP method to connect the HttpClient.

public final HttpClient

Returns:

a new HttpClient
responseTimeout
(Duration
the maximum duration allowed between each network-level read operations (resolution: ms).
maxReadOperationInterval
)

Specifies the maximum duration allowed between each network-level read operation while reading a given response (resolution: ms).

public final HttpClient

Returns:

a new HttpClient
secure
()

Enable default sslContext support.

public final HttpClient

Returns:

a new HttpClient
secure
(Consumer<? super SslProvider.SslContextSpec>
builder callback for further customization of SslContext.
sslProviderBuilder
)

Apply an SSL configuration customization via the passed builder.

public HttpClient

Returns:

a new HttpClient
secure
(SslProvider
The provider to set when configuring SSL
sslProvider
)

Apply an SSL configuration via the passed SslProvider.

public final HttpClient

Returns:

a new HttpClient
tcpConfiguration
(Function<? super TcpClient, ? extends TcpClient>
A TcpClient mapping function to update TCP configuration and return an enriched HttpClient to use.
tcpMapper
)

Deprecated Use the other methods exposed by HttpClient to achieve the same configurations. This method will be removed in version 1.1.0.
Apply a TcpClient mapping function to update TCP configuration and return an enriched HttpClient to use.
public Mono<Void>

Returns:

a Mono representing the completion of the warmup
warmup
()

Overrides reactor.netty.transport.ClientTransport.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
public final HttpClient.WebsocketSender

Returns:

a WebsocketSender ready to consume for response
websocket
()

HTTP Websocket to connect the HttpClient.

public final HttpClient.WebsocketSender

Returns:

a WebsocketSender ready to consume for response
websocket
(WebsocketClientSpec
WebsocketClientSpec for websocket configuration
websocketClientSpec
)

HTTP Websocket to connect the HttpClient.

public final HttpClient
wiretap(boolean
specifies whether the wire logger configuration will be added to the pipeline
enable
)

Overrides reactor.netty.transport.Transport.wiretap.

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.
Inherited from reactor.netty.transport.ClientTransport:
connectconnectNowconnectNowdoAfterResolvedoOnConnectdoOnConnecteddoOnDisconnecteddoOnResolvedoOnResolveErrorhostnoProxyproxyproxyWithSystemPropertiesresolverresolverrunOn