Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Re-enable ResourceHandlerTest for range requests and fix. #12418

Merged
merged 1 commit into from
Oct 24, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Assumptions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.OS;
import org.junit.jupiter.api.extension.ExtendWith;
Expand Down Expand Up @@ -461,7 +460,6 @@ public static Stream<Arguments> rangeScenarios()
String body = response.getContent();

assertThat(response, containsHeaderValue("Content-Type", "multipart/byteranges"));
assertThat(response, containsHeaderValue("Content-Length", String.valueOf(body.length())));

HttpField contentType = response.getField(HttpHeader.CONTENT_TYPE);
String boundary = getContentTypeBoundary(contentType);
Expand Down Expand Up @@ -489,7 +487,6 @@ public static Stream<Arguments> rangeScenarios()
String body = response.getContent();

assertThat(response, containsHeaderValue("Content-Type", "multipart/byteranges"));
assertThat(response, containsHeaderValue("Content-Length", String.valueOf(body.length())));

HttpField contentType = response.getField(HttpHeader.CONTENT_TYPE);
String boundary = getContentTypeBoundary(contentType);
Expand Down Expand Up @@ -519,7 +516,6 @@ public static Stream<Arguments> rangeScenarios()
String body = response.getContent();

assertThat(response, containsHeaderValue("Content-Type", "multipart/byteranges"));
assertThat(response, containsHeaderValue("Content-Length", String.valueOf(body.length())));

HttpField contentType = response.getField(HttpHeader.CONTENT_TYPE);
String boundary = getContentTypeBoundary(contentType);
Expand All @@ -537,7 +533,6 @@ public static Stream<Arguments> rangeScenarios()
);

// test a range request with a file with no suffix, therefore no mimetype

scenarios.addScenario(
"No mimetype resource - no range requested",
"""
Expand Down Expand Up @@ -574,57 +569,55 @@ public static Stream<Arguments> rangeScenarios()
Range: bytes=0-9,20-29,40-49\r
\r
""",
HttpStatus.PARTIAL_CONTENT_206,
(response) ->
{
String body = response.getContent();
HttpStatus.PARTIAL_CONTENT_206,
(response) ->
{
String body = response.getContent();

assertThat(response, containsHeaderValue("Content-Type", "multipart/byteranges"));
assertThat(response, containsHeaderValue("Content-Length", String.valueOf(body.length())));

HttpField contentType = response.getField(HttpHeader.CONTENT_TYPE);
String boundary = getContentTypeBoundary(contentType);
HttpField contentType = response.getField(HttpHeader.CONTENT_TYPE);
String boundary = getContentTypeBoundary(contentType);

assertThat("Boundary expected: " + contentType.getValue(), boundary, notNullValue());
assertThat("Boundary expected: " + contentType.getValue(), boundary, notNullValue());

assertThat(body, containsString("Content-Range: bytes 0-9/80"));
assertThat(body, containsString("Content-Range: bytes 20-29/80"));
assertThat(body, containsString("Content-Range: bytes 0-9/80"));
assertThat(body, containsString("Content-Range: bytes 20-29/80"));

assertThat(response.getContent(), startsWith("--" + boundary));
assertThat(response.getContent(), endsWith(boundary + "--\r\n"));
}
assertThat(response.getContent(), startsWith("--" + boundary));
assertThat(response.getContent(), endsWith(boundary + "--\r\n"));
}
);

scenarios.addScenario(
"No mimetype resource - multiple ranges (x5) with empty range request",
"""
GET /context/nofilesuffix HTTP/1.1\r
Host: localhost\r
Range: bytes=0-9,20-29,40-49,60-60,70-79\r
\r
""",
HttpStatus.PARTIAL_CONTENT_206,
(response) ->
{
String body = response.getContent();
"No mimetype resource - multiple ranges (x5) with empty range request",
"""
GET /context/nofilesuffix HTTP/1.1\r
Host: localhost\r
Range: bytes=0-9,20-29,40-49,60-60,70-79\r
\r
""",
HttpStatus.PARTIAL_CONTENT_206,
(response) ->
{
String body = response.getContent();

assertThat(response, containsHeaderValue("Content-Type", "multipart/byteranges"));
assertThat(response, containsHeaderValue("Content-Length", String.valueOf(body.length())));

HttpField contentType = response.getField(HttpHeader.CONTENT_TYPE);
String boundary = getContentTypeBoundary(contentType);
HttpField contentType = response.getField(HttpHeader.CONTENT_TYPE);
String boundary = getContentTypeBoundary(contentType);

assertThat("Boundary expected: " + contentType.getValue(), boundary, notNullValue());
assertThat("Boundary expected: " + contentType.getValue(), boundary, notNullValue());

assertThat(body, containsString("Content-Range: bytes 0-9/80"));
assertThat(body, containsString("Content-Range: bytes 20-29/80"));
assertThat(body, containsString("Content-Range: bytes 40-49/80"));
assertThat(body, containsString("Content-Range: bytes 60-60/80")); // empty range
assertThat(body, containsString("Content-Range: bytes 70-79/80"));
assertThat(body, containsString("Content-Range: bytes 0-9/80"));
assertThat(body, containsString("Content-Range: bytes 20-29/80"));
assertThat(body, containsString("Content-Range: bytes 40-49/80"));
assertThat(body, containsString("Content-Range: bytes 60-60/80")); // empty range
assertThat(body, containsString("Content-Range: bytes 70-79/80"));

assertThat(response.getContent(), startsWith("--" + boundary));
assertThat(response.getContent(), endsWith(boundary + "--\r\n"));
}
assertThat(response.getContent(), startsWith("--" + boundary));
assertThat(response.getContent(), endsWith(boundary + "--\r\n"));
}
);

return scenarios.stream();
Expand Down Expand Up @@ -3115,7 +3108,6 @@ public void testProgrammaticCustomCompressionFormats() throws Exception

@ParameterizedTest
@MethodSource("rangeScenarios")
@Disabled
public void testRangeRequests(ResourceHandlerTest.Scenario scenario) throws Exception
{
FS.ensureDirExists(docRoot);
Expand Down
Loading