Skip to content

Commit

Permalink
Revert "Encode filenames to UTF-8 in Content-Disposition header. (#16…
Browse files Browse the repository at this point in the history
…556)"

Breaks AppResource404, BrowserFrameIsVisible and FlashIsVisible

This reverts commit af6dd56.

Change-Id: I82fc9ef4c9d08dc8aa48e0fa137fae5782701389
  • Loading branch information
Legioth authored and makoivis committed Mar 6, 2015
1 parent 14db3f8 commit 21329bc
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 61 deletions.
30 changes: 10 additions & 20 deletions server/src/com/vaadin/server/DownloadStream.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@
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;
Expand Down Expand Up @@ -282,9 +280,16 @@ public void writeResponse(VaadinRequest request, VaadinResponse response)
}
}

// 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) {
Expand Down Expand Up @@ -312,21 +317,6 @@ public void writeResponse(VaadinRequest request, VaadinResponse response)
}
}

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.
Expand Down
6 changes: 6 additions & 0 deletions server/src/com/vaadin/server/FileDownloader.java
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,12 @@ public boolean handleConnectorRequest(VaadinRequest request,
}
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()) {
Expand Down
41 changes: 0 additions & 41 deletions server/tests/src/com/vaadin/server/FileDownloaderTests.java

This file was deleted.

0 comments on commit 21329bc

Please sign in to comment.