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)
Deprecated.
since 1.4, use
connectTimeout(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.
|
MutableHeaders |
getHeaders() |
URI |
getUri()
The request URI.
|
default URI |
getUrl()
Deprecated.
since 1.4, use
getUri() |
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.
|
RequestSpec |
method(HttpMethod method)
Specifies the request method.
|
default RequestSpec |
method(String 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) |
default RequestSpec |
readTimeoutSeconds(int seconds)
Deprecated.
since 1.4, use
connectTimeout(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.
|
default RequestSpec |
sslContext(Factory<SSLContext> factory)
Deprecated.
since 1.5, no replacement.
|
RequestSpec |
sslContext(SslContext sslContext)
Sets the
SslContext used for client and server SSL authentication. |
RequestSpec |
sslContext(SSLContext sslContext)
Deprecated.
since 1.5, use
sslContext(SslContext) |
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
@Deprecated RequestSpec sslContext(SSLContext sslContext)
sslContext(SslContext)
SSLContext
used for client and server SSL authentication.sslContext
- SSL context with keystore as well as trust storeRequestSpec
@Deprecated 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 actionRequestSpec sslContext(SslContext sslContext)
SslContext
used for client and server SSL authentication.sslContext
- SSL context with keystore as well as trust storeRequestSpec
SslContextBuilder.forClient()
MutableHeaders getHeaders()
MutableHeaders
that can be used to configure the headers that will be used for the request.RequestSpec maxContentLength(int numBytes)
numBytes
- the maximum response length to acceptthis
RequestSpec responseMaxChunkSize(int numBytes)
Defaults to the configured HttpClientSpec.responseMaxChunkSize(int)
for the corresponding client.
Increasing this value can increase throughput at the expense of memory use.
numBytes
- the max number of bytes to emitthis
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.default RequestSpec method(String method)
method
- the methodRequestSpec method(HttpMethod method)
method
- the methoddefault RequestSpec get()
this
default RequestSpec post()
this
default RequestSpec put()
this
default RequestSpec delete()
this
default RequestSpec patch()
this
default RequestSpec options()
this
default RequestSpec head()
this
RequestSpec decompressResponse(boolean shouldDecompress)
shouldDecompress
- whether to enable decompressionURI getUri()
@Deprecated default URI getUrl()
getUri()
@Deprecated default RequestSpec connectTimeoutSeconds(int seconds)
connectTimeout(Duration)
RequestSpec connectTimeout(Duration duration)
This value defaults to 30 seconds.
duration
- the socket connection timeoutthis
@Deprecated default RequestSpec readTimeoutSeconds(int seconds)
connectTimeout(Duration)
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