The Cyrillic characters in the Filename parameter of Content-Disposition header
Good morning, dear Habra-users.
There was a following problem. I have a web application (client: js, server php script) and some file storage. To download a file from the repository, the client part of the web application sends a request to the server, there is performed the business logic (authorization, etc.), if all OK, then given the link to the file. Then the client part redirects to this link. On the file storage server is nginx, which gives files. The names of the files are a set of symbols without semantic content (just a GUID), which is not much liked by the users. They wanted to when downloading a file had the same name as the corresponding entity in the web application. Because to rename the file it would not be desirable for some reason, came up with the following:
1. In the formation of links in the backend of the web application to it clings the GET parameter that contains acceptable to the user the file name.
2. In nginx configuration, when the impact file is supplied with this parameter in the Content-Disposition header.
(add_header Content-Disposition 'attachment;Filename=$args';)
The problems started with the substitution in the Content-Disposition of the Russian text.
First off, when firefox was redirected to a repository makes urlencode links. And nginx Content-Disposition inserts the encoded string. Accordingly, firefox offers to save the file under a coded name.
Second, even if Content-Disposition is non-encoded string, but UTF-8 with Cyrillic, then IE doesn't want to know anything about what is UTF-8. Interpreterpath it as cp1251 and name of the file is obtained with gibberish.
In General, this scheme works properly only in chrome. If I'm not mistaken, with the problem number 1 (urlencode) can be overcome if to recompile nginx from source to include a module ngx_set_misc. Then in the nginx configuration you can use set_unescape_uri to do urldecode for the file name before inserting it in the Content-Disposition header. But this option would be a last resort.
And how to solve the problem with IE — I don't know.
In General, I'm stumped. I would be very grateful for the advice, maybe there is much more simple way to solve my problem, but I in an emphasis do not see.