将单个 HTTP 标头的多个值添加到请求或响应的标准
如果我想添加值列表作为 HTTP 标头,是否有标准方法可以做到这一点?我在 RFC 822 中找不到任何内容(我可以轻松理解)。例如,是 逗号分隔值标准或分号分隔值。有标准吗?
例子:
Key: value1;value2;value3
If I want to add a list of values as an HTTP Header, is there a standard way to do this? I couldn't find anything (that I could easily understand) in RFC 822. For example, is
comma separated values standard or semi-colon separated values. Is there a standard at all?
Example:
Key: value1;value2;value3
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您需要查看 HTTP 规范 RFC 2616< /a> 上面写着:
这意味着您可以在具有不同值的响应中多次发送相同的标头,只要这些值可以使用逗号相互附加即可。这也意味着您可以通过用逗号连接多个值来在单个标头中发送多个值。
所以在你的情况下它将是:
You'll want to take a look at the HTTP spec RFC 2616 where it says:
What this means is that you can send the same header multiple times in a response with different values, as long as those values can be appended to each other using a comma. This also means that you can send multiple values in a single header by concatenating them with commas.
So in your case it will be:
无论如何@marc-novakowski你缩小了“问题”的范围:)
但我们将检查一个简单的情况:
当彼此之间的值是用逗号分隔 - 出现昏迷的情况???
那么“客户”的责任是选择并决定策略,例如删除、合并 (如果合并如何)?
请查看 nsHttpHeaderArray 的 Mozilla 实现
https://github.com/bnoordhuis/mozilla-central/blob/master/netwerk/protocol/http/nsHttpHeaderArray.h#L185
我鼓励您在遇到这种情况时在常见的现有解决方案中进行搜索 - 因为它们提供了熟悉的方案
标志说明:
请再看一遍句子:
根据 HTTP 规范,我们使用逗号 ',' 将每个值与其他值分隔开 - 这里没有 cookie 一词:)
也许我们需要精确地讨论 HEADER字段(s - 重复时)“Cookie-set”是一个标头字段并且它具有值..我们认为这些值是“COOKIE/S” - 因此客户端/服务器实现应该处理这样的“COOKIE/S”
查看值或名称对:)在HTTP 1/1 SPEC
https://datatracker.ietf.org/doc/html/rfc7230#section-3.2.2
by all means @marc-novakowski you narrowing the "problem" :)
but we will examine a simple case:
how do you join such headers when the values one from another are delimited with commas - case when coma can appear ???
then the "client" responsibility is to choose and decide the strategy eg drop, merg (if merg how)?
pleas take look at Mozilla implementation of nsHttpHeaderArray
https://github.com/bnoordhuis/mozilla-central/blob/master/netwerk/protocol/http/nsHttpHeaderArray.h#L185
I encourage when you face a such situation to search in common existing solutions - as they providing familiar scheme
flags explanations:
please look one more time for sentence:
per HTTP spec we delimit each value from other using a comma ',' - there is no word cookie here :)
maybe we need to precise we talk here about HEADER FIELD(s - when repeating them) "Cookie-set" is a header field and it has value .. those value we consider to be a "COOKIE/S" - thus client/server implementation should handle such "COOKIE/S"
SEE VALUES OR NAME PAIRS :) IN HTTP 1/1 SPEC
https://datatracker.ietf.org/doc/html/rfc7230#section-3.2.2
然而,并非所有具有相同字段名称的值都可以组合到字段值列表中。例如,在 RFC 7230 中,我们可以阅读
However not all values with the same field name may be combined into field values list. For example, in RFC 7230 we may read