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

Using range length for content-length header #1213

Merged
merged 1 commit into from Aug 31, 2017
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -348,7 +348,8 @@ protected Response getBinaryContent(final String rangeValue)
new RangeRequestInputStream(binary.getContent(), range.start(), range.size());

builder = status(PARTIAL_CONTENT).entity(rangeInputStream)
.header("Content-Range", contentRangeValue);
.header("Content-Range", contentRangeValue)
.header(CONTENT_LENGTH, range.size());
}

} else {
Expand Down
Expand Up @@ -40,6 +40,7 @@
import static javax.ws.rs.core.Response.Status.NOT_MODIFIED;
import static javax.ws.rs.core.Response.Status.NO_CONTENT;
import static javax.ws.rs.core.Response.Status.OK;
import static javax.ws.rs.core.Response.Status.PARTIAL_CONTENT;
import static javax.ws.rs.core.Response.Status.PRECONDITION_FAILED;
import static javax.ws.rs.core.Response.Status.TEMPORARY_REDIRECT;
import static javax.ws.rs.core.Response.Status.UNSUPPORTED_MEDIA_TYPE;
Expand Down Expand Up @@ -1503,6 +1504,24 @@ public void testGetDatastream() throws IOException, ParseException {
}
}

@Test
public void testGetLongRange() throws IOException, ParseException {
final String id = getRandomUniqueId();
createObjectAndClose(id);
final StringBuffer buf = new StringBuffer();
while ( buf.length() < 9000 ) {
buf.append("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");
}
createDatastream(id, "ds1", buf.toString());

final HttpGet get = getDSMethod(id, "ds1");
get.setHeader("Range", "bytes=0-8199");
try (final CloseableHttpResponse response = execute(get)) {
assertEquals("Expected 206 Partial Content!", PARTIAL_CONTENT.getStatusCode(), getStatus(response));
assertEquals("Expected range length (8200)!", "8200", response.getFirstHeader(CONTENT_LENGTH).getValue());
}
}

@Test
public void testDeleteDatastream() throws IOException {
final String id = getRandomUniqueId();
Expand Down
Expand Up @@ -51,4 +51,16 @@ public void shouldAcceptUnboundedRanges() throws IOException {
assertEquals("0123456789", s);
}
}

@Test
public void getGetLongRange() throws IOException {
final StringBuffer buf = new StringBuffer();
while ( buf.length() < 9000 ) {
buf.append("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");
}
final InputStream in = new ByteArrayInputStream(buf.toString().getBytes());
try (final RangeRequestInputStream out = new RangeRequestInputStream(in, 0L, 9000)) {
assertEquals(9000, IOUtils.toString(out, UTF_8).length());
}
}
}