From b35d44bd4c4f2f12d6c337bc96f53f246df3c4c0 Mon Sep 17 00:00:00 2001 From: Brian Clozel Date: Tue, 24 Nov 2015 21:36:22 +0100 Subject: [PATCH] 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 --- .../web/servlet/resource/ResourceHttpRequestHandler.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/ResourceHttpRequestHandler.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/ResourceHttpRequestHandler.java index d89bb8fb8c2..0b12ef71b60 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/ResourceHttpRequestHandler.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/ResourceHttpRequestHandler.java @@ -574,7 +574,7 @@ public class ResourceHttpRequestHandler extends WebContentGenerator out.write(buffer, 0, (int) bytesToCopy); bytesToCopy = 0; } - if (bytesRead < buffer.length) { + if (bytesRead == -1) { break; } }