]> source.dussan.org Git - vaadin-framework.git/commitdiff
Revert "Encode filenames to UTF-8 in Content-Disposition header. (#16556)"
authorLeif Åstrand <leif@vaadin.com>
Fri, 6 Mar 2015 09:09:27 +0000 (09:09 +0000)
committerVaadin Code Review <review@vaadin.com>
Fri, 6 Mar 2015 09:17:53 +0000 (09:17 +0000)
Breaks AppResource404, BrowserFrameIsVisible and FlashIsVisible

This reverts commit af6dd56e89db8ea8c88f607c4214abcde50dfc94.

Change-Id: I82fc9ef4c9d08dc8aa48e0fa137fae5782701389

server/src/com/vaadin/server/DownloadStream.java
server/src/com/vaadin/server/FileDownloader.java
server/tests/src/com/vaadin/server/FileDownloaderTests.java [deleted file]

index 8b2b933bcc422f66c97ab99f4e0b86d4ba03379f..681c4389671427aaa33a67d087913016f8cd193f 100644 (file)
@@ -20,8 +20,6 @@ import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
 import java.io.Serializable;
-import java.io.UnsupportedEncodingException;
-import java.net.URLEncoder;
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.Map;
@@ -282,9 +280,16 @@ public class DownloadStream implements Serializable {
                     }
                 }
 
-                // Content-Disposition: attachment generally forces download
-                response.setHeader("Content-Disposition",
-                        getContentDispositionValue());
+                // suggest local filename from DownloadStream if
+                // Content-Disposition
+                // not explicitly set
+                String contentDispositionValue = getParameter("Content-Disposition");
+                if (contentDispositionValue == null) {
+                    contentDispositionValue = "filename=\"" + getFileName()
+                            + "\"";
+                    response.setHeader("Content-Disposition",
+                            contentDispositionValue);
+                }
 
                 int bufferSize = getBufferSize();
                 if (bufferSize <= 0 || bufferSize > Constants.MAX_BUFFER_SIZE) {
@@ -312,21 +317,6 @@ public class DownloadStream implements Serializable {
         }
     }
 
-    private String getContentDispositionValue()
-            throws UnsupportedEncodingException {
-        String contentDispositionValue = getParameter("Content-Disposition");
-
-        if (contentDispositionValue == null) {
-            String encodedFilename = URLEncoder.encode(getFileName(), "utf-8");
-
-            contentDispositionValue = String.format(
-                    "attachment; filename=\"%s\"; filename*=utf-8''%s",
-                    encodedFilename, encodedFilename);
-        }
-
-        return contentDispositionValue;
-    }
-
     /**
      * Helper method that tries to close an output stream and ignores any
      * exceptions.
index bea9922c50388d4d0d55a4b6c3b03b0d3e758300..42c2f76e1abe6f6d43fc55d1e2bec3f0b5a628ff 100644 (file)
@@ -141,6 +141,12 @@ public class FileDownloader extends AbstractExtension {
             }
             stream = ((ConnectorResource) resource).getStream();
 
+            if (stream.getParameter("Content-Disposition") == null) {
+                // Content-Disposition: attachment generally forces download
+                stream.setParameter("Content-Disposition",
+                        "attachment; filename=\"" + stream.getFileName() + "\"");
+            }
+
             // Content-Type to block eager browser plug-ins from hijacking
             // the file
             if (isOverrideContentType()) {
diff --git a/server/tests/src/com/vaadin/server/FileDownloaderTests.java b/server/tests/src/com/vaadin/server/FileDownloaderTests.java
deleted file mode 100644 (file)
index 4e9478c..0000000
+++ /dev/null
@@ -1,41 +0,0 @@
-package com.vaadin.server;
-
-import static org.mockito.Matchers.contains;
-import static org.mockito.Matchers.eq;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.verify;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.URLEncoder;
-
-import org.junit.Before;
-import org.junit.Test;
-
-public class FileDownloaderTests {
-    private String filename = "日本語.png";
-    private DownloadStream stream;
-
-    @Before
-    public void setup() {
-        stream = new DownloadStream(mock(InputStream.class), "", filename);
-    }
-
-    @Test
-    public void contentDispositionFilenameIsUtf8Encoded() throws IOException {
-        VaadinResponse response = mock(VaadinResponse.class);
-
-        stream.writeResponse(mock(VaadinRequest.class), response);
-
-        verify(response).setHeader(eq("Content-Disposition"),
-                contains("attachment;"));
-        String encodedFileName = URLEncoder.encode(filename, "utf-8");
-        verify(response).setHeader(eq("Content-Disposition"),
-                contains(String.format("filename=\"%s\";", encodedFileName)));
-        verify(response)
-                .setHeader(
-                        eq("Content-Disposition"),
-                        contains(String.format("filename*=utf-8''%s",
-                                encodedFileName)));
-    }
-}