-
Notifications
You must be signed in to change notification settings - Fork 38.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow repeatable writes in StreamingHttpOutputMessage #31449
Comments
Thanks for the report and sample project. This doesn't appear to be a Spring Boot problem. The following tests illustrate the behavior without using Spring Boot: package com.example.httpclient5demo;
import static org.assertj.core.api.Assertions.assertThat;
import org.apache.hc.client5.http.config.RequestConfig;
import org.apache.hc.client5.http.impl.classic.HttpClientBuilder;
import org.junit.jupiter.api.Test;
import org.springframework.http.client.BufferingClientHttpRequestFactory;
import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
import org.springframework.web.client.RestTemplate;
class Httpclient5DemoApplicationTests {
@Test
void redirectsCanBeEnabled() {
RestTemplate restTemplate = new RestTemplate();
RequestConfig.Builder requestConfig = RequestConfig.custom()
.setRedirectsEnabled(true);
HttpClientBuilder httpClientBuilder = HttpClientBuilder.create()
.setDefaultRequestConfig(requestConfig.build());
HttpComponentsClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory(httpClientBuilder.build());
restTemplate.setRequestFactory(requestFactory);
String response = restTemplate.getForObject("https://httpbin.org/redirect-to?url=https://httpbin.org/base64/SFRUUEJJTiBpcyBhd2Vzb21l", String.class);
assertThat(response).isEqualTo("HTTPBIN is awesome");
}
@Test
void redirectsCanBeEnabledWhenBuffering() {
RestTemplate restTemplate = new RestTemplate();
RequestConfig.Builder requestConfig = RequestConfig.custom()
.setRedirectsEnabled(true);
HttpClientBuilder httpClientBuilder = HttpClientBuilder.create()
.setDefaultRequestConfig(requestConfig.build());
HttpComponentsClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory(httpClientBuilder.build());
restTemplate.setRequestFactory(new BufferingClientHttpRequestFactory(requestFactory));
String response = restTemplate.getForObject("https://httpbin.org/redirect-to?url=https://httpbin.org/base64/SFRUUEJJTiBpcyBhd2Vzb21l", String.class);
assertThat(response).isEqualTo("HTTPBIN is awesome");
}
}
|
Thank you @wilkinsona for analyzing the issue. I updated the example with your test cases. |
I spotted another issue. Basic Auth (401) and Proxy Auth (407) Challenges are not working when buffering is enabled.
The example has been updated with a test case. |
The issue is not a configuration issue, as I assumed initialy. I'll change the issue title accordingly. It is caused by changes introduced in #30557 .
A quick fix would be to not pass in empty But I think the changes in #30557 are problematic in this regard. As it is implemented right now, even requests using the |
Thanks @poutsma , my HttpComponents based test are good again. From reading the code I think at least |
Thanks for spotting that, it should now be fixed. |
@cachescrubber I made some further related changes in 6dd93d4, which should enable repeatable writes for many types of request bodies, meaning that you typically don't need to wrap your request factory in a |
Thanks for the heads-up. I use |
Hi, I found this issue today during my investigation of redirects which stopped working after spring update. PS: Currently, I resolved my redirect issue with wrapping |
@karlovskiy well spotted, this should be fixed in 6.1.4. |
BufferingClientHttpRequestFactory
creates requests which are not repeatableA
RestTemplate
obtained form the following snippet will lose the default request configuration applied to theHttpComponentsClientHttpRequestFactory
, in this case thesetRedirectsEnabled(true)
is not honored.HttpComponentsClientHttpRequestFactory
).I prepared a reproducible example here. Just run com.example.httpclient5demo.Httpclient5DemoApplicationTests
The text was updated successfully, but these errors were encountered: