标题的顺序是否有意义
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/