You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-dev@james.apache.org by ad...@apache.org on 2017/02/14 13:17:13 UTC
[2/2] james-project git commit: JAMES-1941 Add Content-Length in
download response
JAMES-1941 Add Content-Length in download response
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/81c11f96
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/81c11f96
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/81c11f96
Branch: refs/heads/master
Commit: 81c11f96e1467036c2d5baba3d09afcd1a41386f
Parents: 7035956
Author: Antoine Duprat <ad...@linagora.com>
Authored: Tue Feb 14 10:00:03 2017 +0100
Committer: Antoine Duprat <ad...@linagora.com>
Committed: Tue Feb 14 13:13:25 2017 +0100
----------------------------------------------------------------------
.../jmap/methods/integration/cucumber/DownloadStepdefs.java | 5 +++++
.../src/test/resources/cucumber/DownloadGet.feature | 1 +
.../src/main/java/org/apache/james/jmap/DownloadServlet.java | 1 +
3 files changed, 7 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/james-project/blob/81c11f96/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/DownloadStepdefs.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/DownloadStepdefs.java b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/DownloadStepdefs.java
index d000bb3..d74481f 100644
--- a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/DownloadStepdefs.java
+++ b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/DownloadStepdefs.java
@@ -340,6 +340,11 @@ public class DownloadStepdefs {
}
}
+ @Then("^the attachment size is (\\d+)$")
+ public void assertContentLength(int size) throws IOException {
+ assertThat(response.getFirstHeader("Content-Length").getValue()).isEqualTo(String.valueOf(size));
+ }
+
private void assertEncodedFilenameMatches(String name) {
String contentDispositionHeader = response.getHeaders("Content-Disposition")[0].toString();
assertThat(contentDispositionHeader).startsWith(UTF8_CONTENT_DIPOSITION_START);
http://git-wip-us.apache.org/repos/asf/james-project/blob/81c11f96/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/resources/cucumber/DownloadGet.feature
----------------------------------------------------------------------
diff --git a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/resources/cucumber/DownloadGet.feature b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/resources/cucumber/DownloadGet.feature
index 80570cc..fba6926 100644
--- a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/resources/cucumber/DownloadGet.feature
+++ b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/resources/cucumber/DownloadGet.feature
@@ -11,6 +11,7 @@ Feature: Download GET
Given "username@domain.tld" mailbox "INBOX" contains a message "1" with an attachment "2"
When "username@domain.tld" downloads "2"
Then the user should receive that attachment
+ And the attachment size is 3071
Scenario: Getting an attachment with an unknown blobId
Given "username@domain.tld" mailbox "INBOX" contains a message "1" with an attachment "2"
http://git-wip-us.apache.org/repos/asf/james-project/blob/81c11f96/server/protocols/jmap/src/main/java/org/apache/james/jmap/DownloadServlet.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/DownloadServlet.java b/server/protocols/jmap/src/main/java/org/apache/james/jmap/DownloadServlet.java
index 45f5dcc..cd40d57 100644
--- a/server/protocols/jmap/src/main/java/org/apache/james/jmap/DownloadServlet.java
+++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/DownloadServlet.java
@@ -118,6 +118,7 @@ public class DownloadServlet extends HttpServlet {
Attachment attachment = attachmentManager.getAttachment(AttachmentId.from(blobId), mailboxSession);
IOUtils.copy(attachment.getStream(), resp.getOutputStream());
+ resp.setHeader("Content-Length", String.valueOf(attachment.getSize()));
resp.setStatus(SC_OK);
} catch (AttachmentNotFoundException e) {
LOGGER.info(String.format("Attachment '%s' not found", blobId), e);
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org