Skip to content

Commit

Permalink
Add content-length to bitstream
Browse files Browse the repository at this point in the history
  • Loading branch information
wwelling committed Jan 10, 2024
1 parent 64ae49a commit 6be7e4e
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ public ResponseEntity retrieve(@PathVariable UUID uuid, HttpServletResponse resp
.withBufferSize(BUFFER_SIZE)
.withFileName(name)
.withChecksum(bit.getChecksum())
.withLength(bit.getSizeBytes())
.withMimetype(mimetype)
.with(request)
.with(response);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import java.io.IOException;
import java.util.Arrays;
import java.util.Collections;
import java.util.Objects;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

Expand Down Expand Up @@ -143,6 +144,9 @@ public HttpHeaders initialiseHeaders() throws IOException {
if (checksum != null) {
httpHeaders.put(ETAG, Collections.singletonList(checksum));
}
if (Objects.nonNull((Long.valueOf(this.length)))) {
httpHeaders.put(HttpHeaders.CONTENT_LENGTH, Collections.singletonList(String.valueOf(this.length)));
}
httpHeaders.put(LAST_MODIFIED, Collections.singletonList(FastHttpDateFormat.formatDate(lastModified)));
httpHeaders.put(EXPIRES, Collections.singletonList(FastHttpDateFormat.formatDate(
System.currentTimeMillis() + DEFAULT_EXPIRE_TIME)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,18 @@ public void retrieveFullBitstream() throws Exception {
}
context.restoreAuthSystemState();

//** WHEN **
// we want to know what we are downloading before we download it
getClient().perform(head("/api/core/bitstreams/" + bitstream.getID() + "/content"))
//** THEN **
.andExpect(status().isOk())

//The Content Length must match the full length
.andExpect(header().longValue("Content-Length", bitstreamContent.getBytes().length))
.andExpect(header().string("Content-Type", "text/plain;charset=UTF-8"))
.andExpect(header().string("ETag", "\"" + bitstream.getChecksum() + "\""))
.andExpect(content().bytes(new byte[] {}));

//** WHEN **
//We download the bitstream
getClient().perform(get("/api/core/bitstreams/" + bitstream.getID() + "/content"))
Expand All @@ -232,7 +244,7 @@ public void retrieveFullBitstream() throws Exception {
.andExpect(status().isNotModified());

//The download and head request should also be logged as a statistics record
checkNumberOfStatsRecords(bitstream, 2);
checkNumberOfStatsRecords(bitstream, 3);
}

@Test
Expand Down

0 comments on commit 6be7e4e

Please sign in to comment.