Why HTTP servers forbid underscores in HTTP header names

此生再无相见时 提交于 2019-12-17 02:12:16

问题


Few month ago I had a problem with a custom HTTP header named "SESSION_ID", not been transfered by nginx proxy.

I've been told that underscores are prohibited according to RFC of HTTP protocol.

Googling, I've found that most servers like apache or nginx define them as illegal.

RFC2616 section 4.2 says

follow the same generic format as that given in Section 3.1 of RFC 822 [9]

and RFC822 says

The field-name must be composed of printable ASCII characters (i.e., characters that have values between 33. and 126., decimal, except colon)

underscore is 95 decimal character in ASCII table (belongs to 33-126 range). What am I missing?


回答1:


They are not forbidden. It's CGI legacy. Here

If you do not explicitly set underscores_in_headers on;, nginx will silently drop HTTP headers with underscores (which are perfectly valid according to the HTTP standard). This is done in order to prevent ambiguities when mapping headers to CGI variables, as both dashes and underscores are mapped to underscores during that process.




回答2:


Underscores in header fields are allowed (RFC 7230, sec. 3.2.), but indeed uncommon.



来源:https://stackoverflow.com/questions/22856136/why-http-servers-forbid-underscores-in-http-header-names

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