Skip to content
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

InterceptingClientHttpRequest is always buffered despite the delegate [SPR-16380] #20926

Closed
spring-projects-issues opened this issue Jan 15, 2018 · 1 comment
Assignees
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

Comments

@spring-projects-issues
Copy link
Collaborator

spring-projects-issues commented Jan 15, 2018

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:

restTemplate.getInterceptors().add(new OauthAuthorizationInterceptor(accessToken));

Because the file is so large, I was getting an OutOfMemoryException, so I disabled buffering:

HttpComponentsClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory();
requestFactory.setBufferRequestBody(false);
restTemplate = new RestTemplate(requestFactory);

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:

@spring-projects-issues
Copy link
Collaborator Author

spring-projects-issues commented Aug 2, 2018

Rossen Stoyanchev commented

As per the answer to the similar request #21650, we're not going to support this, now that the WebClient is available and provides first-class support for streaming.

@spring-projects-issues spring-projects-issues added status: declined A suggestion or change that we don't feel we should currently apply type: enhancement A general enhancement in: web Issues in web modules (web, webmvc, webflux, websocket) labels Jan 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
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
Projects
None yet
Development

No branches or pull requests

2 participants