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

Add ContentLength support for InputStreamResource created in ResourceHttpMessageConverter and ResourceDecoder #24292

Conversation

ofaizulin
Copy link
Contributor

Issue
InputStreamResource created in ResourceHttpMessageConverter /ResourceDecoder doesn't properly support contentLength.
contentLength() method consumes input stream to calculate size instead of just providing predefined value.

Motivation
Streaming use case, where application acts as a proxy for large amount of data.

Fix
ResourceHttpMessageConverter should read HTTP Content-Length header.
ResourceDecoder creates ISR based on byte array, so size is always known.

Caveats
contentLength() for InputStreamResource created in ResourceHttpMessageConverter can be -1 if Content-Length header is missing.

Added support of HTTP Content-Length header to ResourceHttpMessageConverter for InputStreamResource
Removed contentLength calculation for InputStreamResource in ResourceDecoder since size is always known
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Jan 4, 2020
@rstoyanchev rstoyanchev self-assigned this Jan 6, 2020
@rstoyanchev rstoyanchev added in: web Issues in web modules (web, webmvc, webflux, websocket) type: enhancement A general enhancement and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Jan 6, 2020
@rstoyanchev rstoyanchev added this to the 5.2.3 milestone Jan 6, 2020
@jhoeller jhoeller changed the title Add ContentLegth support for InputStreamResource created in ResourceHttpMessageConverter and ResourceDecoder Add ContentLength support for InputStreamResource created in ResourceHttpMessageConverter and ResourceDecoder Jan 7, 2020
rstoyanchev pushed a commit that referenced this pull request Jan 8, 2020
Expose the known content length, if known, in the InputStreamResource returned by ResourceHttpMessageConverter or
ResourceDecoder.

See gh-24292
rstoyanchev added a commit that referenced this pull request Jan 8, 2020
@rstoyanchev
Copy link
Contributor

Thanks for the pull request. I made a small adjustment to fall back on the base class in case the content-length is not present.

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) type: enhancement A general enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants