Package ratpack.core.http.client
Interface RequestSpec
-
public interface RequestSpec
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static interface
RequestSpec.Body
The request body.
-
Field Summary
Fields Modifier and Type Field Description static int
DEFAULT_MAX_REDIRECTS
The default number of redirects to follow automatically.
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description default RequestSpec
basicAuth(String username, String password)
Adds the appropriate header for HTTP Basic authentication with the given username and password.RequestSpec
body(Action<? super RequestSpec.Body> action)
Executes the given action with therequest body
.RequestSpec
connectTimeout(Duration duration)
Sets the socket connection timeout.RequestSpec
decompressResponse(boolean shouldDecompress)
Enables automatic decompression of the response.default RequestSpec
delete()
Specifies to use the DELETE request method.default RequestSpec
get()
Specifies to use the GET request method.RequestSpec.Body
getBody()
The body of the request, used for specifying the body content.Duration
getConnectTimeout()
Gets the configured socket connection timeout.boolean
getDecompressResponse()
Gets if responses are automatically decompressed.MutableHeaders
getHeaders()
int
getMaxContentLength()
Get the configured maximum response length.HttpMethod
getMethod()
Get the configured request method.Duration
getReadTimeout()
Gets the configured socket read timeout.int
getRedirects()
Get the configured maximum number of redirects.io.netty.handler.ssl.SslContext
getSslContext()
Get the configuredSslContext
used for client and server SSL authentication.Action<? super SSLParameters>
getSslParams()
Get additional configuration, such as SNI names, for the TLS/SSL connection to the server.URI
getUri()
The request URI.default RequestSpec
head()
Specifies to use the HEAD request method.RequestSpec
headers(Action<? super MutableHeaders> action)
This method can be used to buffer changes to the headers.RequestSpec
maxContentLength(int numBytes)
The maximum response length to accept.default RequestSpec
method(String method)
Specifies the request method.RequestSpec
method(HttpMethod method)
Specifies the request method.RequestSpec
onRedirect(Function<? super ReceivedResponse,Action<? super RequestSpec>> function)
Specifies a function to invoke when a redirectable response is received.default RequestSpec
options()
Specifies to use the OPTIONS request method.default RequestSpec
patch()
Specifies to use the PATCH request method.default RequestSpec
post()
Specifies to use the POST request method.default RequestSpec
put()
Specifies to use the PUT request method.RequestSpec
readTimeout(Duration duration)
Sets the socket read timeout.RequestSpec
redirects(int maxRedirects)
The maximum number of redirects to automatically follow, before simply returning the redirect response.RequestSpec
responseMaxChunkSize(int numBytes)
The max size of the chunks to emit when reading a response as a stream.RequestSpec
sslContext(io.netty.handler.ssl.SslContext sslContext)
Sets theSslContext
used for client and server SSL authentication.RequestSpec
sslParams(Action<? super SSLParameters> action)
Sets additional configuration, such as SNI names, for the TLS/SSL connection to the server.
-
-
-
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
-
getSslContext
io.netty.handler.ssl.SslContext getSslContext()
Get the configuredSslContext
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 theSslContext
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
-
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
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
-
body
RequestSpec body(Action<? super RequestSpec.Body> action) throws 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:
Exception
- any thrown byaction
-
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 usernamepassword
- the password- Returns:
this
-
-