且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

处理HTTP标头中的空格

更新时间:2022-04-27 03:05:11

根据 RFC2616 (HTTP/1.1),字段值前面可能有空格,但字段名称前没有空格:

According with paragraph 4.2 of RFC2616 (HTTP/1.1), field values might be preceded by whitespace, but not the field name:

每个标头字段由 的名称,后跟冒号(:")和字段值.栏位名称 不区分大小写.字段值之前可以有任意数量 LWS(线性空白)的大小,但***使用单个SP.通过在每条额外的行之前添加至少一个SP或HT,可以将标头字段扩展到多行.应用程序应遵循通用格式",其中 在生成HTTP构造时,已知或已指出一种,因为 可能存在一些无法接受任何东西的实现.

Each header field consists of a name followed by a colon (":") and the field value. Field names are case-insensitive. The field value may be preceded by any amount of LWS (linear white space), though a single SP is preferred. Header fields can be extended over multiple lines by preceding each extra line with at least one SP or HT. Applications ought to follow "common form", where one is known or indicated, when generating HTTP constructs, since there might exist some implementations that fail to accept anything.