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

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

问题描述

标题的顺序是否有意义

A: 1
B: 2

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:

不同字段名的头部字段的顺序收到的影响不大.然而,这是良好做法".发送首先是general-header字段,然后是request-header或response-头字段,并以实体头字段结尾.

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:

具有相同字段名的多个消息头字段可以是当且仅当该消息的整个字段值出现在消息中标头字段被定义为一个逗号分隔的列表 [即,#(values)].必须可以将多个标头字段合并为一个字段名称:字段值"对,不改变语义消息,通过将每个后续字段值附加到第一个,每个用逗号分隔.头域相同的顺序因此,收到的字段名称对组合字段值的解释,因此代理不得转发消息时更改这些字段值的顺序.

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天全站免登陆