public abstract class HttpClient
extends java.lang.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 java.lang.String |
USER_AGENT |
| Constructor and Description |
|---|
HttpClient() |
| Modifier and Type | Method and Description |
|---|---|
HttpClient |
addressSupplier(java.util.function.Supplier<? extends java.net.SocketAddress> connectAddressSupplier)
The address to which this client should connect for each subscribe.
|
HttpClient |
baseUrl(java.lang.String baseUrl)
Configure URI to use for this request/response
|
HttpClient |
chunkedTransfer()
Enable transfer-encoding
|
HttpClient |
compress()
Enable gzip compression
|
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 |
doOnRequest(java.util.function.BiConsumer<? super HttpClientRequest,? super Connection> doOnRequest)
Setup a callback called when
HttpClientRequest is about to be sent. |
HttpClient |
doOnResponse(java.util.function.BiConsumer<? super HttpClientResponse,? super Connection> doOnResponse)
Setup a callback called after
HttpClientResponse headers have been
received |
HttpClient |
followRedirect()
Enable http status 301/302 auto-redirect support
|
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.
|
static HttpClient |
newConnection()
Prepare an unpooled
HttpClient. |
HttpClient |
noChunkedTransfer()
Disable transfer-encoding
|
HttpClient |
noCompression()
Disable gzip compression
|
HttpClient |
noRedirection()
Disable http status 301/302 auto-redirect support
|
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.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(java.lang.String subprotocols)
HTTP Websocket to connect the
HttpClient. |
HttpClient |
wiretap()
Apply a wire logger configuration using
HttpClient category
and DEBUG logger level |
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(java.lang.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 java.net.SocketAddress> connectAddressSupplier)
connectAddressSupplier - A supplier of the address to connect to.HttpClientpublic final HttpClient compress()
HttpClientpublic final HttpClient followRedirect()
HttpClientpublic final HttpClient chunkedTransfer()
HttpClientpublic final HttpClient.RequestSender delete()
HttpClient.HttpClient.RequestSender ready to prepare the content for responsepublic 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 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 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 sending
websocket handshakeHttpClientpublic final HttpClient noCompression()
HttpClientpublic final HttpClient noRedirection()
HttpClientpublic final HttpClient noChunkedTransfer()
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.RequestSender post()
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 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.HttpClientpublic final HttpClient wiretap()
HttpClient category
and DEBUG logger levelHttpClientpublic final HttpClient.WebsocketSender websocket()
HttpClient.HttpClient.WebsocketSender ready to consume for responsepublic final HttpClient.WebsocketSender websocket(java.lang.String subprotocols)
HttpClient.subprotocols - a websocket subprotocol comma separated listHttpClient.WebsocketSender ready to consume for responseprotected TcpClient tcpConfiguration()
HttpClient chain to use with TcpClient.connect()} or separatelyTcpClient