如何在 HTTP 中对 Content-Disposition 标头的文件名参数进行编码? [英] How to encode the filename parameter of Content-Disposition header in HTTP?

查看:35
本文介绍了如何在 HTTP 中对 Content-Disposition 标头的文件名参数进行编码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

想要强制下载资源而不是直接呈现在 Web 浏览器中的 Web 应用程序会在表单的 HTTP 响应:

Web applications that want to force a resource to be downloaded rather than directly rendered in a Web browser issue a Content-Disposition header in the HTTP response of the form:

Content-Disposition:附件;文件名=文件名

filename 参数可用于建议浏览器将资源下载到的文件的名称.RFC 2183(内容处置),但是,在section 2.3(文件名参数)文件名只能使用US-ASCII字符:

The filename parameter can be used to suggest a name for the file into which the resource is downloaded by the browser. RFC 2183 (Content-Disposition), however, states in section 2.3 (The Filename Parameter) that the file name can only use US-ASCII characters:

当前的 [RFC 2045] 语法限制参数值(因此内容处置文件名)到美国-ASCII.我们承认伟大的允许任意性的可取性文件名中的字符集,但它是超出本文档的范围定义必要的机制.

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.

然而,有经验证据表明,当今最流行的 Web 浏览器似乎允许非 US-ASCII 字符,但(由于缺乏标准)在文件名的编码方案和字符集规范上存在分歧.那么问题是,如果需要将文件名naïvefile"(不带引号,第三个字母是 U+00EF)编码到 Content-Disposition 标头中,流行浏览器采用的各种方案和编码是什么?

There is empirical evidence, nevertheless, that most popular Web browsers today seem to permit non-US-ASCII characters yet (for the lack of a standard) disagree on the encoding scheme and character set specification of the file name. Question is then, what are the various schemes and encodings employed by the popular browsers if the file name "naïvefile" (without quotes and where the third letter is U+00EF) needed to be encoded into the Content-Disposition header?

就这个问题而言,流行的浏览器是:

  • 谷歌浏览器
  • Safari
  • Internet Explorer 或 Edge
  • 火狐
  • 歌剧

推荐答案

在提议的 RFC 5987,超文本传输​​协议 (HTTP) 标头字段参数的字符集和语言编码".

There is discussion of this, including links to browser testing and backwards compatibility, in the proposed RFC 5987, "Character Set and Language Encoding for Hypertext Transfer Protocol (HTTP) Header Field Parameters."

RFC 2183 表明此类标头应根据 RFC 2184,已被 RFC 2231,包含在上面的 RFC 草案中.

RFC 2183 indicates that such headers should be encoded according to RFC 2184, which was obsoleted by RFC 2231, covered by the draft RFC above.

这篇关于如何在 HTTP 中对 Content-Disposition 标头的文件名参数进行编码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆