Skip to content

Commit

Permalink
Fix content-range header length
Browse files Browse the repository at this point in the history
Submitted by Justin Chen.
  • Loading branch information
rmaucher committed Nov 18, 2024
1 parent 05ddeea commit 7d8ff31
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
2 changes: 1 addition & 1 deletion java/org/apache/catalina/servlets/DefaultServlet.java
Original file line number Diff line number Diff line change
Expand Up @@ -2415,7 +2415,7 @@ protected void copy(WebResource resource, long length, ServletOutputStream ostre
}
long start = getStart(range, length);
long end = getEnd(range, length);
ostream.println("Content-Range: bytes " + start + "-" + end + "/" + (end - start));
ostream.println("Content-Range: bytes " + start + "-" + end + "/" + length);
ostream.println();

// Printing content
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ public static Collection<Object[]> parameters() {
// Valid range
parameterSets.add(new Object[] {
"bytes=0-9", null, Integer.valueOf(206), "10", "0-9/" + len });
parameterSets.add(new Object[] {
"bytes=0-9,10-10", null, Integer.valueOf(206), null, "0-9/" + len });
parameterSets.add(new Object[] {
"bytes=-100", null, Integer.valueOf(206), "100", (len - 100) + "-" + (len - 1) + "/" + len });
parameterSets.add(new Object[] {
Expand Down Expand Up @@ -140,7 +142,7 @@ public void testRange() throws Exception {
// Check the result
Assert.assertEquals(responseCodeExpected, rc);

if (contentLengthExpected.length() > 0) {
if (contentLengthExpected != null && contentLengthExpected.length() > 0) {
String contentLength = responseHeaders.get("Content-Length").get(0);
Assert.assertEquals(contentLengthExpected, contentLength);
}
Expand All @@ -151,7 +153,14 @@ public void testRange() throws Exception {
if (headerValues != null && headerValues.size() == 1) {
responseRange = headerValues.get(0);
}
Assert.assertEquals("bytes " + responseRangeExpected, responseRange);
if (responseRange != null) {
Assert.assertEquals("bytes " + responseRangeExpected, responseRange);
} else {
Assert.assertTrue(
"Expected `Content-Range: " + "bytes " + responseRangeExpected +
"` in multipart/byteranges response body not found!",
responseBody.toString().contains("bytes " + responseRangeExpected));
}
}
}

Expand Down
4 changes: 4 additions & 0 deletions webapps/docs/changelog.xml
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,10 @@
The previous fix for incosistent resource metadata during concurrent
reads and writes was incomplete. (markt)
</fix>
<fix>
<pr>780</pr>: Fix <code>content-range</code> header length. Submitted
by Justin Chen. (remm)
</fix>
</changelog>
</subsection>
<subsection name="Coyote">
Expand Down

0 comments on commit 7d8ff31

Please sign in to comment.