You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
RestTemplate should support streaming download and upload [SPR-16885] #21424
in: webIssues in web modules (web, webmvc, webflux, websocket)status: declinedA suggestion or change that we don't feel we should currently applytype: enhancementA general enhancement
ResourceHttpMessageConverter has a boolean supportsReadStreaming, which if set, and the response type is InputStreamResource, returns InputStreamResource; otherwise it returns a ByteArrayResource. So clearly, the intent is supporting streaming download.
However, there is a problem: RestTemplate closes the response soon after the HttpMessageConverter runs. Thus, even if I asked for InputStreamResource, and got it, it's no good, because the response stream has been closed. I think it should be dependent on the response type.
On the writing side, implementations of ClientHttpRequestFactory has a boolean bufferRequestBody but SimpleClientHttpRequestFactory (JDK client) and HttpComponentsClientHttpRequestFactory (Apache HTTP client) support this feature, but not OkHttp3ClientHttpRequestFactory.
As explained in #19448, RestTemplate is not meant to stream the response body; its contract doesn't allow it, and it's been around for so long that changing such a basic part of its behavior cannot be done without disrupting many applications. Please use WebClient instead for such use cases.
in: webIssues in web modules (web, webmvc, webflux, websocket)status: declinedA suggestion or change that we don't feel we should currently applytype: enhancementA general enhancement
Activity
spring-projects-issues commentedon Jun 5, 2018
Brian Clozel commented
As explained in #19448,
RestTemplateis not meant to stream the response body; its contract doesn't allow it, and it's been around for so long that changing such a basic part of its behavior cannot be done without disrupting many applications. Please useWebClientinstead for such use cases.The second part of this issue seems unrelated. Is this about adding request body streaming support for okhttp3 in
RestTemplate? If so, I think we can turn this issue into an enhancement request.