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​(ratpack.func.Function<? super ReceivedResponse,​ratpack.func.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
      • sslContext

        @Deprecated
        RequestSpec sslContext​(javax.net.ssl.SSLContext sslContext)
        Deprecated.
        since 1.5, use sslContext(SslContext)
        Sets the SSLContext used for client and server SSL authentication.
        Parameters:
        sslContext - SSL context with keystore as well as trust store
        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)
      • sslContext

        @Deprecated
        default RequestSpec sslContext​(ratpack.func.Factory<javax.net.ssl.SSLContext> factory)
                                throws java.lang.Exception
        Deprecated.
        since 1.5, no replacement.
        Factory method to create SSLContext used for client and server SSL authentication.
        Parameters:
        factory - provides a factory that will create SSLContext instance
        Returns:
        this
        Throws:
        java.lang.Exception - this can be thrown from the action
      • 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()
      • 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​(ratpack.func.Action<? super MutableHeaders> action)
                     throws java.lang.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:
        java.lang.Exception - This can be thrown from the action supplied.
      • method

        default RequestSpec method​(java.lang.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

        java.net.URI getUri()
        The request URI.
        Returns:
        the request URI
        Since:
        1.4
      • getUrl

        @Deprecated
        default java.net.URI getUrl()
        Deprecated.
        since 1.4, use getUri()
      • connectTimeout

        RequestSpec connectTimeout​(java.time.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

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

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

        This value defaults to 30 seconds.

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

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

        RequestSpec proxy​(ratpack.func.Action<? super ProxySpec> proxy)
        Configure a HTTP proxy for this request.
        Parameters:
        proxy - the proxy configuration
        Returns:
        this
        Since:
        1.10
      • getProxy

        Proxy getProxy()
        The configured proxy instance for this request.
        Returns:
        The configure proxy instance for the request
        Since:
        1.10
      • getBody

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

        RequestSpec body​(ratpack.func.Action<? super RequestSpec.Body> action)
                  throws java.lang.Exception
        Executes the given action with the request body.

        This method is a “fluent API” alternative to getBody().

        Parameters:
        action - configuration of the request body
        Returns:
        this
        Throws:
        java.lang.Exception - any thrown by action
      • basicAuth

        default RequestSpec basicAuth​(java.lang.String username,
                                      java.lang.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