InterceptingClientHttpRequest is always buffered despite the delegate [SPR-16380] #20926
Labels
in: web
Issues in web modules (web, webmvc, webflux, websocket)
status: declined
A suggestion or change that we don't feel we should currently apply
type: enhancement
A general enhancement
Wyatt Smith opened SPR-16380 and commented
When writing an application, I had to upload a large file (~600 MB) using the RestTemplate, as well as use an oAuth2 bearer header. To do this, I added a custom interceptor to write the oauth header:
Because the file is so large, I was getting an OutOfMemoryException, so I disabled buffering:
The application continued getting the memory exception. Upon investigation, it appears as though the ClientHttpRequestFactory is wrapped by an InterceptingClientHttpRequestFactory because of the interceptor (InterceptingHttpAccessor#getRequestFactory). InterceptingClientHttpRequestFactory.getRequestFactory() returns a InterceptingClientHttpRequest, which is a AbstractBufferingClientHttpRequest (InterceptingClientHttpRequestFactory#createRequest). Despite requestFactory.setBufferRequestBody(false), a buffered request is made.
My temporary solution is to manually add the Authorization header everywhere and eliminate the interceptor so InterceptingHttpAccessor#getRequestFactory returns my original HttpComponentsClientHttpRequestFactory with buffering disabled instead of a InterceptingClientHttpRequestFactory wrapping it.
The long term solution should be for the InterceptingClientHttpRequestFactory to be allowed to be streaming instead of buffered.
Affects: 4.3.9
Issue Links:
The text was updated successfully, but these errors were encountered: