http-headers - HTTP 响应中 header 的顺序重要吗?

标签 http-headers

标题的顺序是否有意义

A: 1
B: 2

对比

B:2
A:1

我试图弄清楚是否可以使用字典来存储标题列表,或者它是否需要是某种列表或有序字典。

最佳答案

不,不同名称的 header 并不重要。请参阅RFC 2616 ,第 4.2 节:

The order in which header fields with differing field names are received is not significant. However, it is "good practice" to send general-header fields first, followed by request-header or response- header fields, and ending with the entity-header fields.

但是,对于具有相同名称的多个 header 来说,这确实很重要:

Multiple message-header fields with the same field-name MAY be present in a message if and only if the entire field-value for that header field is defined as a comma-separated list [i.e., #(values)]. It MUST be possible to combine the multiple header fields into one "field-name: field-value" pair, without changing the semantics of the message, by appending each subsequent field-value to the first, each separated by a comma. The order in which header fields with the same field-name are received is therefore significant to the interpretation of the combined field value, and thus a proxy MUST NOT change the order of these field values when a message is forwarded.

关于http-headers - HTTP 响应中 header 的顺序重要吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/750330/

相关文章:

php - 如何在php中设置http响应状态码和消息

javascript - 想要使用 Scrapy 抓取网站,但不确定是否有绕过 javascript 的方法

android - 如何从 Android 访问 Bearer 认证服务

http - 使用 Zapier Webhook 触发器访问请求 header

javascript - 错误: Can't set headers after they are sent in Node/Express

php - 如何在 PHP 中检测站点是否支持 HTTP/2

Apache:摆脱 header 列表中的 Keep-Alive 条目

python - Angular $http 正在发送 OPTIONS 而不是 PUT(不是 POST)

jquery - HttpHeader UTF 编码

erlang - 更改雅司病响应中的特定 header