public interface RequestSpec
Modifier and Type | Interface and Description |
---|---|
static interface |
RequestSpec.Body
The request body.
|
Modifier and Type | Field and Description |
---|---|
static int |
DEFAULT_MAX_REDIRECTS
The default number of redirects to follow automatically.
|
Modifier and Type | Method and 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 the
request body . |
RequestSpec |
connectTimeout(Duration duration)
Sets the socket connection timeout.
|
default RequestSpec |
connectTimeoutSeconds(int seconds)
Sets the socket connection timeout to the given value in seconds.
|
RequestSpec |
decompressResponse(boolean shouldDecompress)
Enables automatic decompression of the response.
|
RequestSpec.Body |
getBody()
The body of the request, used for specifying the body content.
|
MutableHeaders |
getHeaders() |
URI |
getUrl() |
RequestSpec |
headers(Action<? super MutableHeaders> action)
This method can be used to compose changes to the headers.
|
RequestSpec |
method(String method)
Set the HTTP verb to use.
|
RequestSpec |
onRedirect(Function<? super ReceivedResponse,Action<? super RequestSpec>> function)
Specifies a function to invoke when a redirectable response is received.
|
RequestSpec |
readTimeout(Duration duration) |
default RequestSpec |
readTimeoutSeconds(int seconds) |
RequestSpec |
redirects(int maxRedirects)
The maximum number of redirects to automatically follow, before simply returning the redirect response.
|
default RequestSpec |
sslContext(Factory<SSLContext> factory)
Factory method to create
SSLContext used for client and server SSL authentication. |
RequestSpec |
sslContext(SSLContext sslContext)
Sets the
SSLContext used for client and server SSL authentication. |
static final int DEFAULT_MAX_REDIRECTS
redirects(int)
,
Constant Field ValuesRequestSpec redirects(int maxRedirects)
The default value is 10.
The given value must be >= 0.
maxRedirects
- the maximum number of redirects to followRequestSpec onRedirect(Function<? super ReceivedResponse,Action<? super RequestSpec>> function)
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.
function
- the redirection handling strategythis
RequestSpec sslContext(SSLContext sslContext)
SSLContext
used for client and server SSL authentication.sslContext
- SSL context with keystore as well as trust storeRequestSpec
default RequestSpec sslContext(Factory<SSLContext> factory) throws Exception
SSLContext
used for client and server SSL authentication.factory
- provides a factory that will create SSLContext
instanceRequestSpec
Exception
- this can be thrown from the actionMutableHeaders getHeaders()
MutableHeaders
that can be used to configure the headers that will be used for the request.RequestSpec headers(Action<? super MutableHeaders> action) throws Exception
action
- Provide an action that will act on MutableHeaders.Exception
- This can be thrown from the action supplied.RequestSpec method(String method)
method
- which HTTP verb to useRequestSpec decompressResponse(boolean shouldDecompress)
shouldDecompress
- whether to enable decompressionURI getUrl()
default RequestSpec connectTimeoutSeconds(int seconds)
This value defaults to 30 seconds.
seconds
- the socket connection timeout in secondsthis
connectTimeout(Duration)
RequestSpec connectTimeout(Duration duration)
This value defaults to 30 seconds.
duration
- the socket connection timeoutthis
default RequestSpec readTimeoutSeconds(int seconds)
RequestSpec readTimeout(Duration duration)
RequestSpec.Body getBody()
RequestSpec body(Action<? super RequestSpec.Body> action) throws Exception
request body
.
This method is a “fluent API” alternative to getBody()
.
action
- configuration of the request bodyException
- any thrown by action
default RequestSpec basicAuth(String username, String password)
This will replace any previous value set for the "Authorization"
header.
username
- the usernamepassword
- the passwordthis