Description
Alexander Schuetz opened SPR-16921 and commented
We support ranged requests at specific entrypoints in our REST-API (especially for embedding videos and other large documents).
Since we don't work on files and the data is potentially large we cannot use File-resources and don't want to use byte[]. Instead we are using InputStreamResource which only contains the requested range of data as stream.
The controller method sets the status code 206 and also sets the following headers:
- ETag
- Content-Disposition
- Accept-Ranges
- Content-Range
In version 4.3.17.RELEASE everything works fine and i.e. videos are displayed correctly in browsers Chrome, Firefox and InternetExporer.
Upgrading to version 5.0.2 breaks this functionality, since AbstractMessageConverterMethodProcessor tries to handle the ranged-request itself and doesn't recognize that it has already been handled. Thus it calls InputStreamResource.getContentLength() and tries to read the InputStream afterwards which results in an Exception, since the stream can only be read once. => status code 500 is returned.
We needed to return to spring version 4 because of this behaviour.
Affects: 5.0.2
Issue Links:
- IllegalStateException: InputStream has already been read when returning ResponseEntity<InputStreamResource> [SPR-16754] #21295 IllegalStateException: InputStream has already been read when returning ResponseEntity
Referenced from: commits 818e4b0