What encoding to use when interpreting HTTP/1.1 header field value

佐手、 提交于 2019-12-20 04:22:11

问题


In HTTP/1.1 specs I get this when it comes to define headers:

message-header = field-name ":" [ field-value ]

[...]

field-value = *( field-content | LWS )

field-contet = <the OCTETs making up the field-value and consisting of either *TEXT or combinations of token, separators, and quoted-string>

and the definition for OCTET and TEXT is:

OCTET = <any 8-bit sequence of data>

TEXT = <any OCTET except CTLs, but including LWS> ; where CTL refers to control characters from US-ASCII charset.

Question: Now, when it comes to header names (called field-names in definition), the encoding used is US-ASCII (specified in HTTP/1.1 specs), but how would a server application know what encoding to use for header values?

Note: I think it's normal to be US-ASCII encoded, but the definition lets enough room for different situation.


回答1:


The semantics of non-ASCII code points is essentially undefined. Avoid them.

Recipients usually decode using ISO-8859-1, which at least allows recovery later on (because it'll preserve all octets).

(Also: you're looking at the wrong spec; RFC 2616 is obsoleted by RFC 7230)



来源:https://stackoverflow.com/questions/29841394/what-encoding-to-use-when-interpreting-http-1-1-header-field-value

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