Interface RequestSpec


  • public interface RequestSpec
    • Method Detail

      • redirects

        RequestSpec redirects​(int maxRedirects)
        The maximum number of redirects to automatically follow, before simply returning the redirect response.

        The default value is 10.

        The given value must be >= 0.

        Parameters:
        maxRedirects - the maximum number of redirects to follow
        Returns:
        this
      • getRedirects

        int getRedirects()
        Get the configured maximum number of redirects.
        Returns:
        The maximum number of redirects
        Since:
        1.6
        See Also:
        redirects(int)
      • onRedirect

        RequestSpec onRedirect​(Function<? super ReceivedResponse,​Action<? super RequestSpec>> function)
        Specifies a function to invoke when a redirectable response is received.

        If the function returns null, the redirect will not be followed. If it returns an action, it will be followed and the action will be invoked to further configure the request spec. To simply follow the redirect, return Action.noop().

        The function will never be invoked if redirects(int) is set to 0.

        Parameters:
        function - the redirection handling strategy
        Returns:
        this
      • getSslContext

        io.netty.handler.ssl.SslContext getSslContext()
        Get the configured SslContext used for client and server SSL authentication.
        Returns:
        The SslContext used for SSL authentication
        Since:
        1.6
        See Also:
        sslContext(SslContext)
      • getSslParams

        Action<? super SSLParameters> getSslParams()
        Get additional configuration, such as SNI names, for the TLS/SSL connection to the server.
        Returns:
        additional configuration properties for TLS/SSL connection.
        Since:
        2.0
      • sslContext

        RequestSpec sslContext​(io.netty.handler.ssl.SslContext sslContext)
        Sets the SslContext used for client and server SSL authentication.
        Parameters:
        sslContext - SSL context with keystore as well as trust store
        Returns:
        the RequestSpec
        See Also:
        SslContextBuilder.forClient()
      • sslParams

        RequestSpec sslParams​(Action<? super SSLParameters> action)
        Sets additional configuration, such as SNI names, for the TLS/SSL connection to the server.
        Parameters:
        action - the additional configuration to apply.
        Returns:
        this
        Since:
        2.0
      • getHeaders

        MutableHeaders getHeaders()
        Returns:
        MutableHeaders that can be used to configure the headers that will be used for the request.
      • maxContentLength

        RequestSpec maxContentLength​(int numBytes)
        The maximum response length to accept.
        Parameters:
        numBytes - the maximum response length to accept
        Returns:
        this
        Since:
        1.4
      • getMaxContentLength

        int getMaxContentLength()
        Get the configured maximum response length.
        Returns:
        The maximum response length
        Since:
        1.6
        See Also:
        maxContentLength(int)
      • responseMaxChunkSize

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

        Defaults to the configured HttpClientSpec.responseMaxChunkSize(int) for the corresponding client.

        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
      • headers

        RequestSpec headers​(Action<? super MutableHeaders> action)
                     throws Exception
        This method can be used to buffer changes to the headers.
        Parameters:
        action - Provide an action that will act on MutableHeaders.
        Returns:
        this
        Throws:
        Exception - This can be thrown from the action supplied.
      • method

        default RequestSpec method​(String method)
        Specifies the request method.
        Parameters:
        method - the method
        Returns:
        this
      • method

        RequestSpec method​(HttpMethod method)
        Specifies the request method.
        Parameters:
        method - the method
        Returns:
        this
        Since:
        1.4
      • get

        default RequestSpec get()
        Specifies to use the GET request method.
        Returns:
        this
        Since:
        1.4
      • post

        default RequestSpec post()
        Specifies to use the POST request method.
        Returns:
        this
        Since:
        1.4
      • put

        default RequestSpec put()
        Specifies to use the PUT request method.
        Returns:
        this
        Since:
        1.4
      • delete

        default RequestSpec delete()
        Specifies to use the DELETE request method.
        Returns:
        this
        Since:
        1.4
      • patch

        default RequestSpec patch()
        Specifies to use the PATCH request method.
        Returns:
        this
        Since:
        1.4
      • options

        default RequestSpec options()
        Specifies to use the OPTIONS request method.
        Returns:
        this
        Since:
        1.4
      • head

        default RequestSpec head()
        Specifies to use the HEAD request method.
        Returns:
        this
        Since:
        1.4
      • decompressResponse

        RequestSpec decompressResponse​(boolean shouldDecompress)
        Enables automatic decompression of the response.
        Parameters:
        shouldDecompress - whether to enable decompression
        Returns:
        this
      • getDecompressResponse

        boolean getDecompressResponse()
        Gets if responses are automatically decompressed.
        Returns:
        Whether response decompression is enabled
        Since:
        1.6
        See Also:
        decompressResponse(boolean)
      • getUri

        URI getUri()
        The request URI.
        Returns:
        the request URI
        Since:
        1.4
      • connectTimeout

        RequestSpec connectTimeout​(Duration duration)
        Sets the socket connection timeout.

        This value defaults to 30 seconds.

        Parameters:
        duration - the socket connection timeout
        Returns:
        this
        Since:
        1.1
      • getConnectTimeout

        Duration getConnectTimeout()
        Gets the configured socket connection timeout.
        Returns:
        The socket connection timeout
        Since:
        1.6
        See Also:
        connectTimeout(Duration)
      • readTimeout

        RequestSpec readTimeout​(Duration duration)
        Sets the socket read timeout.

        This value defaults to 30 seconds.

        Parameters:
        duration - the socket read timeout
        Returns:
        this
      • getReadTimeout

        Duration getReadTimeout()
        Gets the configured socket read timeout.
        Returns:
        The socket read timeout
        Since:
        1.6
        See Also:
        readTimeout(Duration)
      • getBody

        RequestSpec.Body getBody()
        The body of the request, used for specifying the body content.
        Returns:
        the (writable) body of the request
      • basicAuth

        default RequestSpec basicAuth​(String username,
                                      String password)
        Adds the appropriate header for HTTP Basic authentication with the given username and password.

        This will replace any previous value set for the "Authorization" header.

        Parameters:
        username - the username
        password - the password
        Returns:
        this