Interface HttpClientSpec


  • public interface HttpClientSpec
    An additive specification of a HTTP client.

    See HttpClient.of(Action).

    Since:
    1.4
    • Method Detail

      • byteBufAllocator

        HttpClientSpec byteBufAllocator​(io.netty.buffer.ByteBufAllocator byteBufAllocator)
        The buffer allocator to use.

        Defaults to ByteBufAllocator.DEFAULT.

        Parameters:
        byteBufAllocator - the buffer allocator
        Returns:
        this
      • execController

        HttpClientSpec execController​(ExecController execController)
        The exec controller to associate with.

        Defaults to ExecController.current(), when the HttpClient is constructed.

        If the HTTP client is being constructed outside of a managed thread, explicitly specifying the execution controller may be necessary dependending on the configuration of the HTTP client.

        Parameters:
        execController - the execution controller
        Returns:
        this
        Since:
        1.9
      • poolSize

        HttpClientSpec poolSize​(int poolSize)
        The maximum number of connections to maintain to a given protocol/host/port.

        Defaults to 0.

        Setting this number to > 0 enables connection pooling (a.k.a. HTTP Keep Alive). The given value dictates the number of connections to a given target, not the overall size. Calling HttpClient.close() will close all current connections.

        Parameters:
        poolSize - the connection pool size
        Returns:
        this
      • poolQueueSize

        HttpClientSpec poolQueueSize​(int poolQueueSize)
        The maximum number of requests that will be queued if connection pool was depleted.

        Defaults to Integer.MAX_VALUE.

        Setting this option is recommended, because the http client queues requests when the pool is depleted. Once a connection is available, the request is processed and all resources released.

        The option is not applied if pool size is not set.

        Parameters:
        poolQueueSize - the connection pool queue size
        Returns:
        this
        Since:
        1.6
      • idleTimeout

        HttpClientSpec idleTimeout​(Duration idleTimeout)
        The default amount of time to allow a connection to remain idle in the connection pool.

        If the connection is idle for the timeout value, it will be closed.

        A value of Duration.ZERO is interpreted as no timeout. The value is never Duration.isNegative().

        Returns:
        this
        Since:
        1.7
      • readTimeout

        HttpClientSpec readTimeout​(Duration readTimeout)
        The read timeout value for responses.

        Defaults to 30 seconds.

        Parameters:
        readTimeout - the read timeout value for responses
        Returns:
        this
      • connectTimeout

        HttpClientSpec connectTimeout​(Duration connectTimeout)
        The connect timeout value for requests.

        Defaults to 30 seconds.

        Parameters:
        connectTimeout - the connect timeout value for requests
        Returns:
        this
        Since:
        1.5
      • responseMaxChunkSize

        HttpClientSpec responseMaxChunkSize​(int numBytes)
        The max size of the chunks to emit when reading a response as a stream.

        Defaults to 8192.

        Increasing this value can increase throughput at the expense of memory use.

        Parameters:
        numBytes - the max number of bytes to emit
        Returns:
        this
        Since:
        1.5
      • requestIntercept

        HttpClientSpec requestIntercept​(Action<? super RequestSpec> interceptor)
        Add an interceptor for all requests handled by this client.

        This function is additive.

        Parameters:
        interceptor - the action to perform on the spec before transmitting.
        Returns:
        this
        Since:
        1.6
      • responseIntercept

        HttpClientSpec responseIntercept​(Action<? super HttpResponse> interceptor)
        Add an interceptor for all responses returned by this client.

        This function is additive.

        Parameters:
        interceptor - the action to perform on the response before returning.
        Returns:
        this
        Since:
        1.6
      • responseIntercept

        HttpClientSpec responseIntercept​(Operation operation)
        Execute the provide Operation for all responses returned by this client.

        This function will wrap the provided operation and subscribe to it. This function is additive with responseIntercept(Action).

        Parameters:
        operation - the operation to subscribe to before return the response.
        Returns:
        this
        Since:
        1.6
      • errorIntercept

        HttpClientSpec errorIntercept​(Action<? super Throwable> interceptor)
        Add an interceptor for errors thrown by this client (eg. connection refused, timeouts)

        This function is additive.

        Parameters:
        interceptor - the action to perform on the error before propagating.
        Returns:
        this
        Since:
        1.6
      • enableMetricsCollection

        HttpClientSpec enableMetricsCollection​(boolean enableMetricsCollection)
        Enable metric collection on HTTP Client.

        Defaults to false.

        Parameters:
        enableMetricsCollection - A boolean used to enable metric collection.
        Returns:
        this
        Since:
        1.6
      • proxy

        HttpClientSpec proxy​(Action<? super ProxySpec> proxy)
        Configure a HTTP proxy for outgoing calls from this client.
        Parameters:
        proxy - the proxy configuration
        Returns:
        this
        Since:
        1.8
      • addressResolver

        HttpClientSpec addressResolver​(io.netty.resolver.AddressResolverGroup<?> resolver)
        Specifies a custom name resolver to use.
        Parameters:
        resolver - the resolver group
        Returns:
        this
        Since:
        1.9
      • addressResolver

        HttpClientSpec addressResolver​(Action<? super io.netty.resolver.dns.DnsNameResolverBuilder> resolver)
        Specifies a custom name resolver to use.
        Parameters:
        resolver - the configuration of the resolver to use
        Returns:
        this
        Since:
        1.9
      • useJdkAddressResolver

        default HttpClientSpec useJdkAddressResolver()
        Specifies that the JDK name resolver should be used.

        This option should only be used when it is absolutely necessary to use the JDK implementation. By default, a Netty based implementation is used that provides better performance.

        Returns:
        this
        Since:
        1.9