Closed
Description
BufferingClientHttpRequestFactory
creates requests which are not repeatable
A RestTemplate
obtained form the following snippet will lose the default request configuration applied to the HttpComponentsClientHttpRequestFactory
, in this case the setRedirectsEnabled(true)
is not honored.
- Affected Version: spring-boot 3.2.0-M3
- Works with stable: spring-boot 3.1.4
- Affected http client library is Apache HttpComponents 5 (
HttpComponentsClientHttpRequestFactory
).
I prepared a reproducible example here. Just run com.example.httpclient5demo.Httpclient5DemoApplicationTests
RestTemplate restTemplate = restTemplateBuilder
.requestFactory(() -> {
RequestConfig.Builder requestConfig = RequestConfig.custom()
.setRedirectsEnabled(true);
HttpClientBuilder httpClientBuilder = HttpClientBuilder.create()
.setDefaultRequestConfig(requestConfig.build());
HttpComponentsClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory(httpClientBuilder.build());
//return requestFactory;
return new BufferingClientHttpRequestFactory(requestFactory);
})
.rootUri("https://httpbin.org")
.build();
String response = restTemplate.getForObject("/redirect-to?url=https://httpbin.org/base64/SFRUUEJJTiBpcyBhd2Vzb21l", String.class);
assertThat(response).isEqualTo("HTTPBIN is awesome");