设置多个具有相同名称的HTTP标头? [英] Set more than one HTTP header with the same name?

查看:136
本文介绍了设置多个具有相同名称的HTTP标头?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

据我所知,HTTP规范允许设置多个具有相同名称的HTTP标头。是否有任何用例(从客户端到服务器,反之亦然)?

As far as I know it is allowed by the HTTP spec to set more than one HTTP header with the same name. Is there any use case to do so (from client to server and vice versa)?

HTTP 1.1第4.2节


多个带有
的message-header字段相同的字段名称可以出现在
a消息中当且仅当该头字段的整个
字段值是
定义为逗号时分隔列表
[即#(值)]。必须有
将多个头字段
组合成一个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.

如果我是没错,不存在需要多个具有相同名称的标题的情况。

If I'm not wrong there is no case where multiple headers with the same name are needed.

推荐答案

由于重复的标题可能会导致各种网络出现问题 - 服务器和API(无论规范如何),我怀疑是否有任何通用用例,这是最佳实践。当然,这并不是说有人在某个地方没有这样做。

Since duplicate headers can cause issues with various web-servers and APIs (regardless of what the spec says), I doubt there is any general purpose use case where this is best practice. That's not to say someone somewhere isn't doing it, of course.

这篇关于设置多个具有相同名称的HTTP标头?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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