-
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
Remove buffering in ClientHttpRequestFactory implementations #30557
Comments
This change breaks implementations where RestTemplate is initialised with These implementations would fail with this excpetion
The issue arised when updating from Spring Boot 3.0.x to 3.2.x. The cause of this is that the MiminalHttpClient does not fall back to inspecting the request object for the target host as InternalHttpClient does. The workaround is simple - instead fo HttpClientBuilder.create()
.setConnectionManager(httpClientManager)
.build() |
The
ClientHttpRequestFactory
hierarchy provides an HTTP client libraries abstraction to theRestTemplate
. This abstraction was introduced in Spring Framework 3.0, when memory constraints are different than they are today. In particular, mostClientHttpRequestFactory
implementations buffer the entire request body in memory before sending it on the wire. Because theClientHttpRequest
exposes the request body through aOutputStream
, and most HTTP client libraries do not expose such a stream, aByteArrayOuputStream
is used, converted to a byte array that is sent as request body.Instead of exposing an output stream, which necessitates buffering the request body, we can store a callback that writes to the HTTP output stream, and use that callback when the HTTP connection has been made. In Spring Framework 4 we introduced the
StreamingHttpOutputMessage
to support this alternative, but this interface was only implemented by the Apache HttpClient request factory.We should review request buffering in the
ClientHttpRequestFactory
hierarchy, and make sure that implementations can support theStreamingHttpOutputMessage
do so.The text was updated successfully, but these errors were encountered: