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 <[email protected]>
Authored: Tue Feb 14 10:00:03 2017 +0100
Committer: Antoine Duprat <[email protected]>
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 "[email protected]" mailbox "INBOX" contains a message "1" with an 
attachment "2"
     When "[email protected]" downloads "2"
     Then the user should receive that attachment
+    And the attachment size is 3071
 
   Scenario: Getting an attachment with an unknown blobId
     Given "[email protected]" 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: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to