Description
The ClientHttpRequestFactory
hierarchy provides an HTTP client libraries abstraction to the RestTemplate
. This abstraction was introduced in Spring Framework 3.0, when memory constraints are different than they are today. In particular, most ClientHttpRequestFactory
implementations buffer the entire request body in memory before sending it on the wire. Because the ClientHttpRequest
exposes the request body through a OutputStream
, and most HTTP client libraries do not expose such a stream, a ByteArrayOuputStream
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 the StreamingHttpOutputMessage
do so.