public class HttpClientConfig extends Object implements Config
Note that you can't configure the redirect settings from this config. Please use RedirectConfig
for this purpose.
Parameter name | Parameter value | Description |
---|---|---|
ClientPNames.COOKIE_POLICY | CookiePolicy.IGNORE_COOKIES | Don't automatically set response cookies in subsequent requests. |
CookieSpecPNames.DATE_PATTERNS | [EEE, dd-MMM-yyyy HH:mm:ss z, EEE, dd MMM yyyy HH:mm:ss z] | Defines valid date patterns to be used for parsing non-standard
expires attribute. |
You can also specify a http client factory that is used to create the http client instances that REST Assured uses (httpClientFactory(HttpClientConfig.HttpClientFactory)
).
By default the DefaultHttpClient
is used. It's also possible to specify whether or not this instance should be reused in multiple requests. By default the http client instance is not reused.
ClientPNames
,
CookiePolicy
,
CoreProtocolPNames
Modifier and Type | Class and Description |
---|---|
static interface |
HttpClientConfig.HttpClientFactory
A factory for creating and configuring a custom http client instance that will be used by REST Assured.
|
Constructor and Description |
---|
HttpClientConfig()
Creates a new HttpClientConfig instance with the
"http.protocol.cookie-policy" parameter set to "ignoreCookies" . |
HttpClientConfig(Map<String,?> httpClientParams)
Creates a new HttpClientConfig instance with the parameters defined by the
httpClientParams . |
Modifier and Type | Method and Description |
---|---|
HttpClientConfig |
addParams(Map<String,?> httpClientParams)
Add the given parameters to an already configured number of parameters.
|
HttpClientConfig |
and() |
HttpClientConfig |
dontReuseHttpClientInstance()
Instruct REST Assured not to reuse the configured http client instance for multiple requests.
|
static HttpClientConfig |
httpClientConfig() |
HttpClientConfig |
httpClientFactory(HttpClientConfig.HttpClientFactory httpClientFactory)
Set the http client factory that Rest Assured should use when making request.
|
org.apache.http.client.HttpClient |
httpClientInstance() |
org.apache.http.entity.mime.HttpMultipartMode |
httpMultipartMode() |
HttpClientConfig |
httpMultipartMode(org.apache.http.entity.mime.HttpMultipartMode httpMultipartMode)
Specify the HTTP Multipart mode when sending multi-part data.
|
boolean |
isConfiguredToReuseTheSameHttpClientInstance()
If this method returns
true then REST Assured will reuse the same HttpClient instance created
by the httpClientInstance() method for all requests. |
boolean |
isUserConfigured() |
Map<String,?> |
params() |
HttpClientConfig |
reuseHttpClientInstance()
Instruct REST Assured to reuse the configured http client instance for multiple requests.
|
<T> HttpClientConfig |
setParam(String parameterName,
T parameterValue)
Set a http client parameter.
|
HttpClientConfig |
setParams(Map<String,?> httpClientParams)
Replaces the currently configured parameters with the ones supplied by
httpClientParams . |
HttpClientConfig |
withParams(Map<String,?> httpClientParams)
Replaces the currently configured parameters with the ones supplied by
httpClientParams . |
public HttpClientConfig()
"http.protocol.cookie-policy"
parameter set to "ignoreCookies"
.public HttpClientConfig and()
public HttpClientConfig reuseHttpClientInstance()
HttpClient
instance for each request. Note that for this to work
the configuration must be defined statically, for example:
RestAssured.config = newConfig().httpClient(httpClientConfig().reuseHttpClientInstance());
httpClientFactory(HttpClientConfig.HttpClientFactory)
public HttpClientConfig dontReuseHttpClientInstance()
reuseHttpClientInstance()
public boolean isConfiguredToReuseTheSameHttpClientInstance()
true
then REST Assured will reuse the same HttpClient
instance created
by the httpClientInstance()
method for all requests. If false
is returned then REST Assured creates a new instance for each request.
By default false
is returned.
RestAssured.config = newConfig().httpClient(httpClientConfig().reuseHttpClientInstance());
true
if the same HTTP Client instance should be reused between several requests, false
otherwise.public <T> HttpClientConfig setParam(String parameterName, T parameterValue)
T
- The parameter typeparameterName
- The name of the parameterparameterValue
- The value of the parameter (may be null)public HttpClientConfig withParams(Map<String,?> httpClientParams)
httpClientParams
. This method is the same as setParams(java.util.Map)
.httpClientParams
- The parameters to set.public HttpClientConfig setParams(Map<String,?> httpClientParams)
httpClientParams
. This method is the same as withParams(java.util.Map)
.httpClientParams
- The parameters to set.public HttpClientConfig addParams(Map<String,?> httpClientParams)
httpClientParams
- The parameters.public HttpClientConfig httpClientFactory(HttpClientConfig.HttpClientFactory httpClientFactory)
httpClientFactory
- The http client factory to use.public org.apache.http.client.HttpClient httpClientInstance()
HttpClient
instances that's used by REST Assured when making a request.public HttpClientConfig httpMultipartMode(org.apache.http.entity.mime.HttpMultipartMode httpMultipartMode)
httpMultipartMode
- The multi-part mode to set.public static HttpClientConfig httpClientConfig()
public org.apache.http.entity.mime.HttpMultipartMode httpMultipartMode()
public boolean isUserConfigured()
isUserConfigured
in interface Config
true
if this config instance has been explicitly configured by the user, false
if it has the default values.Copyright © 2010–2020. All rights reserved.