Is it categorically wrong to send a charset parameter with a Content-Type header for non-text media types?

核能气质少年 提交于 2020-01-15 01:11:47

问题


I've tracked down a bug between two pieces of software, one of them is emitting the header

Content-Type: application/x-bittorrent; charset=utf-8

And the other is handling this incorrectly, but handles it correctly if the charset parameter is dropped. I need to know which software to write a patch for!

According to the W3C's website:

Documents transmitted with HTTP that are of type text, such as text/html, text/plain, etc., can send a charset parameter in the HTTP header to specify the character encoding of the document.

Which implies that documents not of type text should not send this header, I think. However, RFC 2068 states:

The "charset" parameter is used with some media types to define the character set (section 3.4) of the data

I cannot find anywhere in the spec that it is incorrect to add a charset parameter to media types other than text, so my question is: Is the software emitting this header incorrect, or the software consuming it?


回答1:


(1) The relevant spec if RFC 2616, not 2068.

(2) The HTTP spec is correct, it depends on the media type. For instance, you can send a charset parameter for application/xml.

(3) Dunno about application/x-bittorrent - does it have a spec?




回答2:


I think it is incorrect to add a charset parameter for anything other than a text/* media-type, as the spec only permits adding charset for that.



来源:https://stackoverflow.com/questions/6913410/is-it-categorically-wrong-to-send-a-charset-parameter-with-a-content-type-header

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!