Skip to content

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

Closed
ofaizulin wants to merge 1 commit into
spring-projects:masterfrom
ofaizulin:rd-httpmsgconv-fix-isr-contentlength
Closed

Add ContentLength support for InputStreamResource created in ResourceHttpMessageConverter and ResourceDecoder#24292
ofaizulin wants to merge 1 commit into
spring-projects:masterfrom
ofaizulin:rd-httpmsgconv-fix-isr-contentlength

Conversation

@ofaizulin

Copy link
Copy Markdown
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
Copy Markdown
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.

3 participants