Skip to content

RestTemplate should support streaming download and upload [SPR-16885] #21424

Closed

Description

@spring-projects-issues

Abhijit Sarkar opened SPR-16885 and commented

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.


Affects: 5.0.2

Reference URL: https://stackoverflow.com/a/48041200/839733

Issue Links:

Activity

  1. spring-projects-issues commented on Jun 5, 2018

    @spring-projects-issues
    CollaboratorAuthor

    Brian Clozel commented

    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.

    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.

  2. added
    status: declined
    type: enhancement
    in: web
    on Jan 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

in: webstatus: declinedtype: enhancement

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions