flask: send_file fails when filename contains unicode symbols
Hi.
I’ve detected an issue with supporting unicode filenames in send_file.
If send_file attempts to respond with utf-8 in http headers, the answer is empty, the log contains something like “http-headers should containbe latin-1”.
I know that browser support IS A MESS, but it seems, that sending two filenames (filename= and filename*=) separated by semicolon should work.
I’d like this to be handled by flask or werkzeug. Will you accept such pull request?
About this issue
- Original URL
- State: closed
- Created 10 years ago
- Reactions: 2
- Comments: 38 (22 by maintainers)
Commits related to this issue
- Merge pull request #1371 from keyan/update_send_file_docs Update send_file() docs to clarify encoding requirement #1286 — committed to pallets/flask by keyan 9 years ago
- Revert "Update send_file() docs to clarify encoding requirement #1286" — committed to pallets/flask by keyan 9 years ago
- Update send_file() docs to clarify encoding requirement #1286 — committed to pallets/flask by keyan 9 years ago
- Fix send_file to work with non-ascii filenames This commit implements https://tools.ietf.org/html/rfc2231#section-4 in order to support sending unicode characters. Tested on both Firefox and Chromium... — committed to antlarr/flask by antlarr 7 years ago
Similar discussion has already happened regarding this observation. See the issue from
requeststo read more about the details, but the short of it is that HTTP headers are supposed to only acceptlatin-1characters. Changing this behavior in flask or werkzeug would only cause issues and break running code by allowing requests to be sent in an unsupported encoding to webservers which expect to getlatin-1.Someone else can chime in if I am mistaken, but I think this can be closed.
Similar discussion: https://github.com/kennethreitz/requests/issues/1926 https://github.com/jakubroztocil/httpie/issues/212
BTW, I’ve solved the problem by sending filename*=utf-8’blah’ header field. Works everywhere except for the IE <= 8.
Here is the snippet:
Looks like a more correct way of fixing this.