mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-07 01:54:22 +00:00
Add content-length to bitstream
This commit is contained in:
@@ -138,6 +138,7 @@ public class BitstreamRestController {
|
||||
.withBufferSize(BUFFER_SIZE)
|
||||
.withFileName(name)
|
||||
.withChecksum(bit.getChecksum())
|
||||
.withLength(bit.getSizeBytes())
|
||||
.withMimetype(mimetype)
|
||||
.with(request)
|
||||
.with(response);
|
||||
|
@@ -14,6 +14,7 @@ import static javax.mail.internet.MimeUtility.encodeText;
|
||||
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;
|
||||
|
||||
@@ -143,6 +144,9 @@ public class HttpHeadersInitializer {
|
||||
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)));
|
||||
|
@@ -206,6 +206,18 @@ public class BitstreamRestControllerIT extends AbstractControllerIntegrationTest
|
||||
}
|
||||
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"))
|
||||
@@ -232,7 +244,7 @@ public class BitstreamRestControllerIT extends AbstractControllerIntegrationTest
|
||||
.andExpect(status().isNotModified());
|
||||
|
||||
//The download and head request should also be logged as a statistics record
|
||||
checkNumberOfStatsRecords(bitstream, 2);
|
||||
checkNumberOfStatsRecords(bitstream, 3);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
Reference in New Issue
Block a user