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 DefaultServletRangesTest and fix byte ranges for ee10 #8935

Merged
merged 1 commit into from
Nov 24, 2022
Merged
Show file tree
Hide file tree
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 @@ -246,9 +246,10 @@ public static class Part extends MultiPart.Part
{
private final PathContentSource content;

public Part(String contentType, Path path, ByteRange byteRange)
public Part(String contentType, Path path, ByteRange byteRange, long contentLength)
{
this(HttpFields.build().put(HttpHeader.CONTENT_TYPE, contentType), path, byteRange);
this(HttpFields.build().put(HttpHeader.CONTENT_TYPE, contentType)
.put(HttpHeader.CONTENT_RANGE, byteRange.toHeaderValue(contentLength)), path, byteRange);
}

public Part(HttpFields headers, Path path, ByteRange byteRange)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -629,7 +629,7 @@ private void sendData(Request request, Response response, Callback callback, Htt
String boundary = MultiPart.generateBoundary(null, 24);
response.getHeaders().put(HttpHeader.CONTENT_TYPE, contentType + boundary);
MultiPartByteRanges.ContentSource byteRanges = new MultiPartByteRanges.ContentSource(boundary);
ranges.forEach(range -> byteRanges.addPart(new MultiPartByteRanges.Part(content.getContentTypeValue(), content.getResource().getPath(), range)));
ranges.forEach(range -> byteRanges.addPart(new MultiPartByteRanges.Part(content.getContentTypeValue(), content.getResource().getPath(), range, contentLength)));
byteRanges.close();
Content.copy(byteRanges, response, callback);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public void process(Request request, Response response, Callback callback)
String boundary = "boundary";
try (MultiPartByteRanges.ContentSource content = new MultiPartByteRanges.ContentSource(boundary))
{
ranges.forEach(range -> content.addPart(new MultiPartByteRanges.Part("text/plain", resourcePath, range)));
ranges.forEach(range -> content.addPart(new MultiPartByteRanges.Part("text/plain", resourcePath, range, content.getLength())));
content.close();

response.setStatus(HttpStatus.PARTIAL_CONTENT_206);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,13 @@
import org.hamcrest.Matchers;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;

@Disabled
@ExtendWith(WorkDirExtension.class)
public class DefaultServletRangesTest
{
Expand All @@ -45,7 +43,6 @@ public class DefaultServletRangesTest

private Server server;
private LocalConnector connector;
private ServletContextHandler context;

@BeforeEach
public void init() throws Exception
Expand All @@ -55,7 +52,7 @@ public void init() throws Exception
connector = new LocalConnector(server);
connector.getConnectionFactory(HttpConfiguration.ConnectionFactory.class).getHttpConfiguration().setSendServerVersion(false);

context = new ServletContextHandler();
ServletContextHandler context = new ServletContextHandler();
context.setContextPath("/context");
context.setWelcomeFiles(new String[]{"index.html", "index.jsp", "index.htm"});

Expand Down Expand Up @@ -142,7 +139,7 @@ public void testMultipleRangeRequests() throws Exception
"Connection: close\r\n" +
"Range: bytes=0-9,20-29,40-49\r\n" +
"\r\n");
int start = response.indexOf("--jetty");
int start = response.indexOf("--");
String body = response.substring(start);
String boundary = body.substring(0, body.indexOf("\r\n"));
assertResponseContains("206 Partial", response);
Expand Down Expand Up @@ -186,9 +183,9 @@ public void testMultipleSameRangeRequests() throws Exception
"GET /context/data.txt HTTP/1.1\r\n" +
"Host: localhost\r\n" +
"Connection: close\r\n" +
"Range: bytes=" + stringBuilder.toString() + "0-2\r\n" +
"Range: bytes=" + stringBuilder + "0-2\r\n" +
"\r\n");
int start = response.indexOf("--jetty");
int start = response.indexOf("--");
String body = response.substring(start);
String boundary = body.substring(0, body.indexOf("\r\n"));
assertResponseContains("206 Partial", response);
Expand Down