Package ratpack.http.client
Interface RequestSpec
-
public interface RequestSpec
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static interfaceRequestSpec.BodyThe request body.
-
Field Summary
Fields Modifier and Type Field Description static intDEFAULT_MAX_REDIRECTSThe default number of redirects to follow automatically.
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Deprecated Methods Modifier and Type Method Description default RequestSpecbasicAuth(java.lang.String username, java.lang.String password)Adds the appropriate header for HTTP Basic authentication with the given username and password.RequestSpecbody(Action<? super RequestSpec.Body> action)Executes the given action with therequest body.RequestSpecconnectTimeout(java.time.Duration duration)Sets the socket connection timeout.default RequestSpecconnectTimeoutSeconds(int seconds)Deprecated.since 1.4, useconnectTimeout(Duration)RequestSpecdecompressResponse(boolean shouldDecompress)Enables automatic decompression of the response.default RequestSpecdelete()Specifies to use the DELETE request method.default RequestSpecget()Specifies to use the GET request method.RequestSpec.BodygetBody()The body of the request, used for specifying the body content.java.time.DurationgetConnectTimeout()Gets the configured socket connection timeout.booleangetDecompressResponse()Gets if responses are automatically decompressed.MutableHeadersgetHeaders()intgetMaxContentLength()Get the configured maximum response length.HttpMethodgetMethod()Get the configured request method.java.time.DurationgetReadTimeout()Gets the configured socket read timeout.intgetRedirects()Get the configured maximum number of redirects.io.netty.handler.ssl.SslContextgetSslContext()Get the configuredSslContextused for client and server SSL authentication.java.net.URIgetUri()The request URI.default java.net.URIgetUrl()Deprecated.since 1.4, usegetUri()default RequestSpechead()Specifies to use the HEAD request method.RequestSpecheaders(Action<? super MutableHeaders> action)This method can be used to buffer changes to the headers.RequestSpecmaxContentLength(int numBytes)The maximum response length to accept.default RequestSpecmethod(java.lang.String method)Specifies the request method.RequestSpecmethod(HttpMethod method)Specifies the request method.RequestSpeconRedirect(Function<? super ReceivedResponse,Action<? super RequestSpec>> function)Specifies a function to invoke when a redirectable response is received.default RequestSpecoptions()Specifies to use the OPTIONS request method.default RequestSpecpatch()Specifies to use the PATCH request method.default RequestSpecpost()Specifies to use the POST request method.default RequestSpecput()Specifies to use the PUT request method.RequestSpecreadTimeout(java.time.Duration duration)Sets the socket read timeout.default RequestSpecreadTimeoutSeconds(int seconds)Deprecated.since 1.4, usereadTimeout(Duration)RequestSpecredirects(int maxRedirects)The maximum number of redirects to automatically follow, before simply returning the redirect response.RequestSpecresponseMaxChunkSize(int numBytes)The max size of the chunks to emit when reading a response as a stream.RequestSpecsslContext(io.netty.handler.ssl.SslContext sslContext)Sets theSslContextused for client and server SSL authentication.RequestSpecsslContext(javax.net.ssl.SSLContext sslContext)Deprecated.since 1.5, usesslContext(SslContext)default RequestSpecsslContext(Factory<javax.net.ssl.SSLContext> factory)Deprecated.since 1.5, no replacement.
-
-
-
Field Detail
-
DEFAULT_MAX_REDIRECTS
static final int DEFAULT_MAX_REDIRECTS
The default number of redirects to follow automatically.- See Also:
redirects(int), Constant Field Values
-
-
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
-
sslContext
@Deprecated RequestSpec sslContext(javax.net.ssl.SSLContext sslContext)
Deprecated.since 1.5, usesslContext(SslContext)Sets theSSLContextused 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 configuredSslContextused for client and server SSL authentication.- Returns:
- The
SslContextused for SSL authentication - Since:
- 1.6
- See Also:
sslContext(SslContext)
-
sslContext
@Deprecated default RequestSpec sslContext(Factory<javax.net.ssl.SSLContext> factory) throws java.lang.Exception
Deprecated.since 1.5, no replacement.Factory method to createSSLContextused for client and server SSL authentication.- Parameters:
factory- provides a factory that will createSSLContextinstance- Returns:
this- Throws:
java.lang.Exception- this can be thrown from the action
-
sslContext
RequestSpec sslContext(io.netty.handler.ssl.SslContext sslContext)
Sets theSslContextused 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:
MutableHeadersthat 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 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
-
getMethod
HttpMethod getMethod()
Get the configured request method.- Returns:
- The request method.
- Since:
- 1.6
- See Also:
method(HttpMethod)
-
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, usegetUri()
-
connectTimeoutSeconds
@Deprecated default RequestSpec connectTimeoutSeconds(int seconds)
Deprecated.since 1.4, useconnectTimeout(Duration)- Since:
- 1.1
-
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)
-
readTimeoutSeconds
@Deprecated default RequestSpec readTimeoutSeconds(int seconds)
Deprecated.since 1.4, usereadTimeout(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)
-
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(Action<? super RequestSpec.Body> action) throws java.lang.Exception
Executes the given action with therequest 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 byaction
-
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 usernamepassword- the password- Returns:
this
-
-