处理HTTP标头中的空格 [英] Handling whitespaces in http headers

查看:407
本文介绍了处理HTTP标头中的空格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

http请求/响应中应该忽略前导空格还是尾随空格?

Should leading or trailing whitespaces be ignored in an http request/response?

例如,一个HTTP/1.1兼容的客户端应对此进行解释:

For example, should a HTTP/1.1 compliant client interpret this :

Connection  :   close      \r\n

是这样的:

Connection: close\r\n

推荐答案

根据 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.

这篇关于处理HTTP标头中的空格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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