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.
Examples:
HttpClient.create() .baseUrl("http://example.com") .get() .response() .block();HttpClient.create() .post() .uri("http://example.com") .send(Flux.just(bb1, bb2, bb3)) .responseSingle((res, content) -> Mono.just(res.status().code())) .block();HttpClient.create() .baseUri("http://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.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)
The address to which this client should connect for each subscribe.
|
HttpClient |
baseUrl(String baseUrl)
Configure URI to use for this request/response
|
HttpClient |
chunkedTransfer(boolean chunkedEnabled)
Deprecated.
Using
headers(Consumer) for specifying the content length
will disable the transfer-encoding |
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 |
doAfterRequest(java.util.function.BiConsumer<? super HttpClientRequest,? super Connection> doAfterRequest)
Setup a callback called when
HttpClientRequest has been sent |
HttpClient |
doAfterResponse(java.util.function.BiConsumer<? super HttpClientResponse,? super Connection> doAfterResponse)
Setup a callback called after
HttpClientResponse has been fully received. |
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 |
doOnRequest(java.util.function.BiConsumer<? super HttpClientRequest,? super Connection> doOnRequest)
Setup a callback called when
HttpClientRequest is about to be sent. |
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 |
HttpClient |
doOnResponseError(java.util.function.BiConsumer<? super HttpClientResponse,? super Throwable> doOnResponse)
Setup a callback called when
HttpClientResponse has not been fully
received. |
HttpClient |
followRedirect(java.util.function.BiPredicate<HttpClientRequest,HttpClientResponse> predicate)
Enables auto-redirect support if the passed
Predicate matches. |
HttpClient |
followRedirect(boolean followRedirect)
Specifies whether http status 301|302|307|308 auto-redirect support is enabled
|
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.
|
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.RequestSender |
request(HttpMethod method)
Use the passed HTTP method to connect the
HttpClient. |
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(int maxFramePayloadLength)
HTTP Websocket to connect the
HttpClient. |
HttpClient.WebsocketSender |
websocket(String subprotocols)
HTTP Websocket to connect the
HttpClient. |
HttpClient.WebsocketSender |
websocket(String subprotocols,
int maxFramePayloadLength)
HTTP Websocket to connect the
HttpClient. |
HttpClient |
wiretap()
Deprecated.
Use
wiretap(boolean) |
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.HttpClientpublic static HttpClient create(ConnectionProvider connectionProvider)
HttpClient. HttpClient.UriConfiguration.uri(String) or
baseUrl(String) should be invoked before a verb
request(HttpMethod) is selected.HttpClientpublic static HttpClient newConnection()
HttpClient. HttpClient.UriConfiguration.uri(String) or
baseUrl(String) should be invoked after a verb
request(HttpMethod) is selected.HttpClientpublic static HttpClient from(TcpClient tcpClient)
HttpClientHttpClientpublic final HttpClient baseUrl(String baseUrl)
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 addressSupplier(java.util.function.Supplier<? extends SocketAddress> connectAddressSupplier)
connectAddressSupplier - A supplier of the address to connect to.HttpClientpublic final HttpClient compress(boolean compressionEnabled)
compressionEnabled - if true GZip compression/websocket compression extension
is enabled otherwise disabled (default: false)HttpClientpublic 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@Deprecated public final HttpClient chunkedTransfer(boolean chunkedEnabled)
headers(Consumer) for specifying the content length
will disable the transfer-encodingchunkedEnabled - if true transfer-encoding is enabled otherwise disabled.
(default: true)HttpClientpublic final HttpClient cookie(Cookie cookie)
cookie - a cookie to append to the request(s)HttpClientpublic final HttpClient cookie(String name, java.util.function.Consumer<? super Cookie> cookieBuilder)
cookieBuilder - the header Consumer to invoke before requestingHttpClientpublic final HttpClient cookiesWhen(String name, java.util.function.Function<? super Cookie,Mono<? extends Cookie>> cookieBuilder)
cookieBuilder - the cookies Function to invoke before sendingHttpClientpublic final HttpClient cookieCodec(ClientCookieEncoder encoder)
ClientCookieEncoder, ClientCookieDecoder will be
chosen based on the encoderencoder - the preferred ClientCookieEncoderHttpClientpublic final HttpClient cookieCodec(ClientCookieEncoder encoder, ClientCookieDecoder decoder)
ClientCookieEncoder and ClientCookieDecoderencoder - the preferred ClientCookieEncoderdecoder - the preferred ClientCookieDecoderHttpClientpublic 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 connected eventsdoOnResponse - a consumer observing response failuresHttpClientpublic final HttpClient doOnRequest(java.util.function.BiConsumer<? super HttpClientRequest,? super Connection> doOnRequest)
HttpClientRequest is about to be sent.doOnRequest - a consumer observing connected eventsHttpClientpublic 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 connected eventsHttpClientpublic final HttpClient doAfterRequest(java.util.function.BiConsumer<? super HttpClientRequest,? super Connection> doAfterRequest)
HttpClientRequest has been sentdoAfterRequest - a consumer observing connected eventsHttpClientpublic final HttpClient doOnResponse(java.util.function.BiConsumer<? super HttpClientResponse,? super Connection> doOnResponse)
HttpClientResponse headers have been
receiveddoOnResponse - a consumer observing connected eventsHttpClientpublic final HttpClient doOnResponseError(java.util.function.BiConsumer<? super HttpClientResponse,? super Throwable> doOnResponse)
HttpClientResponse has not been fully
received.doOnResponse - a consumer observing response failuresHttpClientpublic final HttpClient doAfterResponse(java.util.function.BiConsumer<? super HttpClientResponse,? super Connection> doAfterResponse)
HttpClientResponse has been fully received.doAfterResponse - a consumer observing disconnected eventsHttpClientpublic 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 requestingHttpClientpublic final HttpClient headersWhen(java.util.function.Function<? super HttpHeaders,Mono<? extends HttpHeaders>> headerBuilder)
headerBuilder - the header Function to invoke before sendingHttpClientpublic final HttpClient keepAlive(boolean keepAlive)
keepAlive - true if keepAlive should be enabled (default: true)HttpClientpublic final HttpClient followRedirect(boolean followRedirect)
followRedirect - if true http status 301/302 auto-redirect support
is enabled otherwise disabled (default: true)HttpClientpublic 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.
predicate - that returns true to enable auto-redirect support.HttpClientpublic final HttpClient observe(ConnectionObserver observer)
Channel
has been connected and after it has been disconnected.observer - a consumer observing state changesHttpClientpublic 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.HttpClientpublic 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 supportHttpClientpublic 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 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.HttpClientpublic 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.HttpClientpublic 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@Deprecated public final HttpClient wiretap()
wiretap(boolean)HttpClient category
and DEBUG logger levelHttpClientpublic final HttpClient wiretap(boolean enable)
HttpClient category
and DEBUG logger levelenable - Specifies whether the wire logger configuration will be added to
the pipelineHttpClientpublic 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 optionsHttpClientpublic final HttpClient.WebsocketSender websocket()
HttpClient.HttpClient.WebsocketSender ready to consume for responsepublic final HttpClient.WebsocketSender websocket(String subprotocols)
HttpClient.subprotocols - a websocket subprotocol comma separated listHttpClient.WebsocketSender ready to consume for responsepublic final HttpClient.WebsocketSender websocket(int maxFramePayloadLength)
HttpClient.maxFramePayloadLength - maximum allowable frame payload lengthHttpClient.WebsocketSender ready to consume for responsepublic final HttpClient.WebsocketSender websocket(String subprotocols, int maxFramePayloadLength)
HttpClient.subprotocols - a websocket subprotocol comma separated listmaxFramePayloadLength - maximum allowable frame payload lengthHttpClient.WebsocketSender ready to consume for responseprotected TcpClient tcpConfiguration()
HttpClient chain to use with TcpClient.connect()} or separatelyTcpClient