Package ratpack.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 Deprecated Methods Modifier and Type Method Description 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.RequestSpec
body(ratpack.func.Action<? super RequestSpec.Body> action)
Executes the given action with therequest body
.RequestSpec
connectTimeout(java.time.Duration duration)
Sets the socket connection timeout.default RequestSpec
connectTimeoutSeconds(int seconds)
Deprecated.since 1.4, useconnectTimeout(Duration)
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.java.time.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.Proxy
getProxy()
The configured proxy instance for this request.java.time.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.java.net.URI
getUri()
The request URI.default java.net.URI
getUrl()
Deprecated.since 1.4, usegetUri()
default RequestSpec
head()
Specifies to use the HEAD request method.RequestSpec
headers(ratpack.func.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(java.lang.String method)
Specifies the request method.RequestSpec
method(HttpMethod method)
Specifies the request method.RequestSpec
onRedirect(ratpack.func.Function<? super ReceivedResponse,ratpack.func.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.RequestSpec
proxy(ratpack.func.Action<? super ProxySpec> proxy)
Configure a HTTP proxy for this request.default RequestSpec
put()
Specifies to use the PUT request method.RequestSpec
readTimeout(java.time.Duration duration)
Sets the socket read timeout.default RequestSpec
readTimeoutSeconds(int seconds)
Deprecated.since 1.4, usereadTimeout(Duration)
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
sslContext(javax.net.ssl.SSLContext sslContext)
Deprecated.since 1.5, usesslContext(SslContext)
default RequestSpec
sslContext(ratpack.func.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(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, usesslContext(SslContext)
Sets theSSLContext
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 configuredSslContext
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 createSSLContext
used for client and server SSL authentication.- Parameters:
factory
- provides a factory that will createSSLContext
instance- Returns:
this
- Throws:
java.lang.Exception
- this can be thrown from the action
-
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()
-
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
-
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)
-
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 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
-
-