Reputation: 4307
I'm testing an endpoint that returns a Location
header with spaces ( it can't be fixed ) and I receive org.apache.http.ClientProtocolException
. According to other answers, I have to create RedirectStrategy
and encode spaces with %20
.
Looking through the documentation I found a small section about HTTP Client
config but it seems it contains only basic info.
How can I set RedirectStrategy
to RestAssured
to encode spaces in the Location
header with %20
?
Upvotes: 2
Views: 1523
Reputation: 40510
The HttpClientConfig allows you to set a custom HttpClient instance to which you can specify the redirect strategy. Unfortunately the HttpClient instance must extend org.apache.http.impl.client.AbstractHttpClient
in order to work with REST Assured. Here's an example that should work:
given().config(RestAssured.config().httpClient(HttpClientConfig.httpClientConfig().httpClientFactory(() -> {
DefaultHttpClient httpClient = new DefaultHttpClient();
httpClient.setRedirectStrategy(..);
return httpClient;
}))). ..
You can also configure this for all tests:
RestAssured.config = RestAssured.config().httpClient(HttpClientConfig.httpClientConfig().httpClientFactory(() -> {
DefaultHttpClient httpClient = new DefaultHttpClient();
httpClient.setRedirectStrategy(..);
return httpClient;
});
Or in a request specification.
Upvotes: 2