HTTP响应中的标头顺序是否重要? [英] Does the order of headers in an HTTP response ever matter?

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

问题描述

标题的顺序是否

A: 1
B: 2

vs

B:2
A:1

我想知道我是否可以使用字典来存储标题列表,或者它是否需要某种列表或有序字典。

I'm trying to figure out if I can use a dictionary to store a list of headers or if it needs to be some kind of list or ordered dictionary.

推荐答案

不,对于具有不同名称的标题无关紧要。请参阅 RFC 2616 ,第4.2节:

No, it does not matter for headers with different names. See RFC 2616, section 4.2:


具有不同字段名称的标题字段的接收顺序是
并不重要。但是,首先发送
通用标头字段,然后是request-header或response-
标头字段,并以entity-header字段结束是良好做法。

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.

但是,对于具有相同名称的多个标题,这很重要:

It DOES matter, however, for multiple headers with the same name:


当且仅当该
头字段的整个字段值被定义为以逗号分隔的列表时,具有相同字段名称的多个消息头字段可以是
。即,#(值)]。
必须可以将多个头字段组合成一个
field-name:field-value对,而不需要通过附加每个后续字段值来更改
消息的语义到第一个,每个
用逗号分隔。因此,接收具有相同
字段名称的头字段的顺序对于组合字段值的
解释是重要的,因此代理必须不是
更改这些字段的顺序转发邮件时的值。

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响应中的标头顺序是否重要?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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