HTTP 应答中的 Content-Disposition 首部,是遵循 MIME 规范中的相关定义的,
一般我们会通过类似: Content-Disposition: inline;filename=foo.bar 的形式
给客户端提示文件名,但如果文件名包含 ASCII 以外的字符时应该怎么处理呢?
在 RFC 2183 (Communicating Presentation Information in Internet Messages)
中,关于 Content-Disposition 的 filename 域有如下叙述:
Current [RFC 2045] grammar restricts parameter values (and hence
Content-Disposition filenames) to US-ASCII. We recognize the great
desirability of allowing arbitrary character sets in filenames, but
it is beyond the scope of this document to define the necessary
mechanisms. We expect that the basic [RFC 1521] `value'
specification will someday be amended to allow use of non-US-ASCII
characters, at which time the same mechanism should be used in the
Content-Disposition filename parameter.
Beyond the limitation to US-ASCII, the sending MUA may wish to bear
in mind the limitations of common filesystems. Many have severe
length and character set restrictions. Short alphanumeric filenames
are least likely to require modification by the receiving system.
所以事实上 Content-Disposition 的 filename 域应当只包含 ASCII 字符,
目前水木附件中如果出现中文文件名,用的其实是 GBK 编码的字符,这对许多
默认以 UTF-8 处理的系统/浏览器造成了困扰,是否可能找到办法改善这一困难
呢?
--
FROM 211.66.100.*