Class HttpClient


public abstract class HttpClient extends ClientTransport<HttpClient,HttpClientConfig>
An HttpClient allows building in a safe immutable way an http client that is materialized and connecting when 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
  • Field Details

    • USER_AGENT

      public static final String USER_AGENT
  • Constructor Details

    • HttpClient

      public HttpClient()
  • Method Details

    • create

      public static HttpClient create()
      Prepare a pooled HttpClient. HttpClient.UriConfiguration.uri(String) or baseUrl(String) should be invoked before a verb request(HttpMethod) is selected.
      Returns:
      a HttpClient
    • create

      public static HttpClient create(ConnectionProvider connectionProvider)
      Prepare an HttpClient. HttpClient.UriConfiguration.uri(String) or baseUrl(String) should be invoked before a verb request(HttpMethod) is selected.
      Parameters:
      connectionProvider - the ConnectionProvider to be used
      Returns:
      a HttpClient
    • from

      @Deprecated public static 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. 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 logging
       
       

      Configuration via the other methods exposed by HttpClient

       
       HttpClient.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 logging
       
       

      Wire logging in plain text

       
       HttpClient.wiretap("logger", LogLevel.DEBUG, AdvancedByteBufFormat.TEXTUAL)
       
       
      Returns:
      a new HttpClient
    • newConnection

      public static HttpClient newConnection()
      Prepare an unpooled HttpClient. HttpClient.UriConfiguration.uri(String) or baseUrl(String) should be invoked after a verb request(HttpMethod) is selected.
      Returns:
      a HttpClient
    • baseUrl

      public final HttpClient baseUrl(String baseUrl)
      Configure URI to use for this request/response.

      Note: Configured baseUrl only applies when used with HttpClient.UriConfiguration.uri(String) or HttpClient.UriConfiguration.uri(Mono).

      Parameters:
      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.
      Returns:
      the appropriate sending or receiving contract
    • compress

      public final HttpClient compress(boolean compressionEnabled)
      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

      public final HttpClient cookie(Cookie cookie)
      Apply cookies configuration.
      Parameters:
      cookie - a cookie to append to the request(s)
      Returns:
      a new HttpClient
    • cookie

      @Deprecated public final HttpClient cookie(String name, Consumer<? super Cookie> cookieBuilder)
      Deprecated.
      as of 1.1.0. Use cookie(Cookie) for configuring cookies. This will be removed in 2.0.0.
      Apply cookies configuration.
      Parameters:
      cookieBuilder - the header Consumer to invoke before requesting
      Returns:
      a new HttpClient
    • cookieCodec

      @Deprecated public final HttpClient cookieCodec(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.
      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.
      Parameters:
      encoder - the preferred ClientCookieEncoder
      decoder - 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 cookies Function to invoke before sending
      Returns:
      a new HttpClient
    • delete

      public final HttpClient.RequestSender delete()
      HTTP DELETE to connect the HttpClient.
      Returns:
      a HttpClient.RequestSender ready to prepare the content for response
    • disableRetry

      public final HttpClient disableRetry(boolean disableRetry)
      Option to disable 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.

      Parameters:
      disableRetry - true to disable retry 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 when HttpClientRequest has been sent and HttpClientState.REQUEST_SENT has been emitted.
      Parameters:
      doAfterRequest - a callback called when HttpClientRequest has been sent
      Returns:
      a new HttpClient
    • doAfterResponseSuccess

      public final HttpClient doAfterResponseSuccess(BiConsumer<? super HttpClientResponse,? super Connection> doAfterResponseSuccess)
      Setup a callback called after HttpClientResponse has been fully received and HttpClientState.RESPONSE_COMPLETED has been emitted.
      Parameters:
      doAfterResponseSuccess - a callback called after HttpClientResponse has been fully received and HttpClientState.RESPONSE_COMPLETED has 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 when 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.

      Parameters:
      doOnRequestError - a consumer observing request failures
      doOnResponseError - a consumer observing response failures
      Returns:
      a new HttpClient
    • doOnRedirect

      public final HttpClient doOnRedirect(BiConsumer<? super HttpClientResponse,? super Connection> doOnRedirect)
      Setup a callback called after 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).

      Parameters:
      doOnRedirect - a callback called after HttpClientResponse headers 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 when HttpClientRequest is about to be sent and HttpClientState.REQUEST_PREPARED has been emitted.
      Parameters:
      doOnRequest - a callback called when HttpClientRequest is about to be sent
      Returns:
      a new HttpClient
    • doOnRequestError

      public final HttpClient doOnRequestError(BiConsumer<? super HttpClientRequest,? super Throwable> doOnRequestError)
      Setup a callback called when 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.
      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 after HttpClientResponse headers have been received and HttpClientState.RESPONSE_RECEIVED has been emitted.
      Parameters:
      doOnResponse - a callback called after HttpClientResponse headers have been received
      Returns:
      a new HttpClient
    • doOnResponseError

      public final HttpClient doOnResponseError(BiConsumer<? super HttpClientResponse,? super Throwable> doOnResponseError)
      Setup a callback called when HttpClientResponse has not been fully received, HttpClientState.RESPONSE_INCOMPLETE has been emitted.
      Parameters:
      doOnResponseError - a consumer observing response failures
      Returns:
      a new HttpClient
    • followRedirect

      public final HttpClient followRedirect(BiPredicate<HttpClientRequest,HttpClientResponse> predicate)
      Enables auto-redirect support if the passed 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).

      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 of followRedirect(BiPredicate) that also accepts BiConsumer that provides the headers from the previous request and the current redirect request.

      Note: The sensitive headers:

      • Expect
      • Cookie
      • Authorization
      • Proxy-Authorization
      are removed from the initialized request when redirecting to a different domain, they can be re-added using the 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; 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.
      Returns:
      a new HttpClient
      Since:
      0.9.12
    • followRedirect

      public final HttpClient followRedirect(BiPredicate<HttpClientRequest,HttpClientResponse> predicate, @Nullable Consumer<HttpClientRequest> redirectRequestConsumer)
      Variant of followRedirect(BiPredicate) that also accepts a redirect request processor.

      Note: The sensitive headers:

      • Expect
      • Cookie
      • Authorization
      • Proxy-Authorization
      are removed from the initialized request when redirecting to a different domain, they can be re-added using 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; use HttpClientInfos.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

      public final HttpClient followRedirect(boolean followRedirect)
      Specifies whether HTTP status 301|302|303|307|308 auto-redirect support is enabled.

      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).

      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 of followRedirect(boolean) that also accepts BiConsumer that provides the headers from the previous request and the current redirect request.

      Note: The sensitive headers:

      • Expect
      • Cookie
      • Authorization
      • Proxy-Authorization
      are removed from the initialized request when redirecting to a different domain, they can be re-added using the 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; 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.
      Returns:
      a new HttpClient
      Since:
      0.9.12
    • followRedirect

      public final HttpClient followRedirect(boolean followRedirect, @Nullable Consumer<HttpClientRequest> redirectRequestConsumer)
      Variant of followRedirect(boolean) that also accepts a redirect request processor.

      Note: The sensitive headers:

      • Expect
      • Cookie
      • Authorization
      • Proxy-Authorization
      are removed from the initialized request when redirecting to a different domain, they can be re-added using 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; use HttpClientInfos.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

      public final HttpClient.ResponseReceiver<?> get()
      HTTP GET to connect the HttpClient.
      Returns:
      a HttpClient.RequestSender ready to consume for response
    • head

      public final HttpClient.ResponseReceiver<?> head()
      HTTP HEAD to connect the HttpClient.
      Returns:
      a HttpClient.RequestSender ready to consume for response
    • headers

      public final HttpClient headers(Consumer<? super HttpHeaders> headerBuilder)
      Apply headers configuration.
      Parameters:
      headerBuilder - the header Consumer to 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 header Function to invoke before sending
      Returns:
      a new HttpClient
    • http2Settings

      public final HttpClient http2Settings(Consumer<Http2SettingsSpec.Builder> http2Settings)
      Apply HTTP/2 configuration.
      Parameters:
      http2Settings - configures Http2SettingsSpec before requesting
      Returns:
      a new HttpClient
    • http3Settings

      @Incubating public final HttpClient http3Settings(Consumer<Http3SettingsSpec.Builder> http3Settings)
      Apply HTTP/3 configuration.
      Parameters:
      http3Settings - configures Http3SettingsSpec before requesting
      Returns:
      a new HttpClient
      Since:
      1.2.0
    • httpMessageLogFactory

      public final HttpClient httpMessageLogFactory(HttpMessageLogFactory httpMessageLogFactory)
      When HttpMessage is 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 DecoderException message 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 the HttpClientCodec's response decoding options.
      Parameters:
      responseDecoderOptions - a function to mutate the provided Http response decoder options
      Returns:
      a new HttpClient
    • keepAlive

      public final HttpClient keepAlive(boolean 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

      public final HttpClient metrics(boolean enable, Function<String,String> uriTagValue)
      Whether to enable metrics to be collected and registered in Micrometer's 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 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 it
      uriTagValue - a function that receives the actual uri and returns the uri tag value that will be used for the metrics with Metrics.URI tag
      Returns:
      a new HttpClient
      Since:
      0.9.7
    • metrics

      public final HttpClient metrics(boolean enable, Supplier<? extends ChannelMetricsRecorder> recorder)
      Description copied from class: Transport
      Specifies whether the metrics are enabled on the Transport. 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 the Transport).
      Overrides:
      metrics in class Transport<HttpClient,HttpClientConfig>
      Parameters:
      enable - if true enables the metrics on the Transport.
      recorder - a supplier for the ChannelMetricsRecorder
      Returns:
      a new Transport reference
    • metrics

      public final HttpClient metrics(boolean enable, Supplier<? extends ChannelMetricsRecorder> recorder, Function<String,String> uriValue)
      Specifies whether the metrics are enabled on the HttpClient. 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 the HttpClient).

      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.

      Parameters:
      enable - true enables metrics collection; false disables it
      recorder - a supplier for the metrics recorder that receives the collected metrics
      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.
      Returns:
      a new HttpClient
    • noSSL

      public final HttpClient noSSL()
      Removes any previously applied SSL configuration customization.
      Returns:
      a new HttpClient
    • observe

      public final HttpClient observe(ConnectionObserver observer)
      Description copied from class: Transport
      Set or add the given ConnectionObserver to observe the connection state changes.
      Overrides:
      observe in class Transport<HttpClient,HttpClientConfig>
      Parameters:
      observer - the ConnectionObserver to be set or add
      Returns:
      a new Transport reference
    • options

      public final HttpClient.ResponseReceiver<?> options()
      HTTP OPTIONS to connect the HttpClient.
      Returns:
      a HttpClient.RequestSender ready to consume for response
    • patch

      public final HttpClient.RequestSender patch()
      HTTP PATCH to connect the HttpClient.
      Returns:
      a HttpClient.RequestSender ready to finalize request and consume for response
    • port

      public final HttpClient port(int port)
      The port to which this client should connect. If a port is not specified, the default port 80 is used.

      Note: The port can be specified also with PORT environment variable.

      Overrides:
      port in class ClientTransport<HttpClient,HttpClientConfig>
      Parameters:
      port - the port to connect to
      Returns:
      a new HttpClient
    • post

      public final HttpClient.RequestSender post()
      HTTP POST to connect the HttpClient.
      Returns:
      a HttpClient.RequestSender ready to finalize request and consume for response
    • protocol

      public final HttpClient protocol(HttpProtocol... supportedProtocols)
      The HTTP protocol to support. Default is HttpProtocol.HTTP11.
      Parameters:
      supportedProtocols - The various HttpProtocol this client will support
      Returns:
      a new HttpClient
    • put

      public final HttpClient.RequestSender put()
      HTTP PUT to connect the HttpClient.
      Returns:
      a HttpClient.RequestSender ready to finalize request and consume for response
    • remoteAddress

      public final HttpClient remoteAddress(Supplier<? extends SocketAddress> remoteAddressSupplier)
      Description copied from class: ClientTransport
      The address to which this client should connect on each subscribe.
      Overrides:
      remoteAddress in class ClientTransport<HttpClient,HttpClientConfig>
      Parameters:
      remoteAddressSupplier - A supplier of the address to connect to.
      Returns:
      a new ClientTransport
    • request

      public HttpClient.RequestSender request(HttpMethod method)
      Use the passed HTTP method to connect the HttpClient.
      Parameters:
      method - the HTTP method to send
      Returns:
      a HttpClient.RequestSender ready to finalize request and consume for response
    • responseTimeout

      public final HttpClient responseTimeout(@Nullable Duration maxReadOperationInterval)
      Specifies the maximum duration allowed between each network-level read operation while reading a given response (resolution: ms). In other words, ReadTimeoutHandler is added to the channel pipeline after sending the request and is removed when the response is fully received. If the maxReadOperationInterval is null, any previous setting will be removed and no maxReadOperationInterval will be applied. If the maxReadOperationInterval is less than 1ms, then 1ms will be the maxReadOperationInterval. The maxReadOperationInterval setting on HttpClientRequest level overrides any maxReadOperationInterval setting on HttpClient level.
      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

      public final HttpClient secure()
      Enable default sslContext support.

      By default SslContext is initialized with:

      • 10 seconds handshake timeout unless the environment property reactor.netty.tcp.sslHandshakeTimeout is set
      • 3 seconds close_notify flush timeout
      • 0 second close_notify read timeout
      • hostname verification enabled

      Returns:
      a new HttpClient
    • secure

      public final HttpClient secure(Consumer<? super SslProvider.SslContextSpec> sslProviderBuilder)
      Apply an SSL configuration customization via the passed builder.

      The builder will produce the SslContext with:

      • 10 seconds handshake timeout unless the passed builder sets another configuration or the environment property reactor.netty.tcp.sslHandshakeTimeout is set
      • 3 seconds close_notify flush timeout
      • 0 second close_notify read timeout
      • hostname verification enabled

      Parameters:
      sslProviderBuilder - builder callback for further customization of SslContext.
      Returns:
      a new HttpClient
    • secure

      public HttpClient secure(SslProvider sslProvider)
      Apply an SSL configuration via the passed SslProvider.

      Note: Hostname verification is not enabled by default. If hostname verification is needed, please apply the HttpClientSecurityUtils.HOSTNAME_VERIFICATION_CONFIGURER configuration to the SslProvider:

       
       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 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.

      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 logging
       
       

      Configuration via the other methods exposed by HttpClient

       
       HttpClient.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 logging
       
       

      Wire logging in plain text

       
       HttpClient.wiretap("logger", LogLevel.DEBUG, AdvancedByteBufFormat.TEXTUAL)
       
       
      Parameters:
      tcpMapper - A TcpClient mapping function to update TCP configuration and return an enriched HttpClient to use.
      Returns:
      a new HttpClient
    • warmup

      public Mono<Void> 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
      By default, when method is not used, the first request absorbs the extra time needed to load resources.
      Overrides:
      warmup in class ClientTransport<HttpClient,HttpClientConfig>
      Returns:
      a Mono representing 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 HttpClient reference
      Since:
      1.2.3
    • websocket

      public final HttpClient.WebsocketSender websocket()
      HTTP Websocket to connect the HttpClient.
      Returns:
      a HttpClient.WebsocketSender ready to consume for response
    • websocket

      public final HttpClient.WebsocketSender websocket(WebsocketClientSpec websocketClientSpec)
      HTTP Websocket to connect the HttpClient.
      Parameters:
      websocketClientSpec - WebsocketClientSpec for websocket configuration
      Returns:
      a HttpClient.WebsocketSender ready to consume for response
      Since:
      0.9.7
    • wiretap

      public final HttpClient wiretap(boolean enable)
      Description copied from class: Transport
      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.
      Overrides:
      wiretap in class Transport<HttpClient,HttpClientConfig>
      Parameters:
      enable - specifies whether the wire logger configuration will be added to the pipeline
      Returns:
      a new Transport reference