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

查看:25
本文介绍了设置多个具有相同名称的 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 节:

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

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.

推荐答案

由于重复的标头可能会导致各种 Web 服务器和 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天全站免登陆