Skip to content

Commit b35d44b

Browse files
committed
Fix inputstream reading for HTTP range requests
Prior to this commit, range requests would be served by ResourceHttpRequestHandler by partially reading the inputstream of static resources. In case of resources contained in ZIP/JAR containers, InputStreams may not fill the entire read buffer when calling `inputStream.read(byte[])`. This was the case when using Spring Boot's ZipInflaterInputStream - this would then not read the entire file content and would close the response without writing the expected body length indicated in the "Content-Length" header. This commit makes sure that the whole resource is read. Issue: SPR-13661
1 parent 20a286b commit b35d44b

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

spring-webmvc/src/main/java/org/springframework/web/servlet/resource/ResourceHttpRequestHandler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -574,7 +574,7 @@ private void copyRange(InputStream in, OutputStream out, long start, long end) t
574574
out.write(buffer, 0, (int) bytesToCopy);
575575
bytesToCopy = 0;
576576
}
577-
if (bytesRead < buffer.length) {
577+
if (bytesRead == -1) {
578578
break;
579579
}
580580
}

0 commit comments

Comments
 (0)