是否可以接受重复的 HTTP 响应标头? [英] Are Duplicate HTTP Response Headers acceptable?
问题描述
我没有找到任何关于标准是否允许重复的 HTTP 响应头的规范,但我需要知道这是否会导致兼容性问题.
假设我有一个这样的响应头:
HTTP/1.1 302 暂时移动服务器:Apache-Coyote/1.1X-Powered-By:Servlet 2.4;JBoss-4.0.3SP1(构建:CVSTag=JBoss_4_0_3_SP1 日期=200510231054)/Tomcat-5.5缓存控制:无缓存缓存控制:无存储位置:http://localhost:9876/foo.bar内容语言:en-US内容长度:0日期:2010 年 12 月 6 日星期一 21:18:26 GMT
请注意,有两个 Cache-Control
标头具有不同的值.浏览器是否总是将它们视为写成Cache-Control: no-cache, no-store"?
是
HTTP RFC2616 可用 这里 说:p><块引用>
可能存在多个具有相同字段名的消息头字段在消息中当且仅当该标头的整个字段值字段被定义为逗号分隔的列表 [即,#(values)].它必须可以将多个标题字段合并为一个field-name: field-value"对,不改变语义消息,通过将每个后续字段值附加到第一个,每个用逗号分隔.头域相同的顺序因此,收到的字段名称对解释很重要的组合字段值,因此代理不得更改转发消息时这些字段值的顺序
因此,如果将整个字段值定义为以逗号分隔的值列表,则具有相同名称的多个标头是可以的(www-authenticate 就是这种情况).
这里记录了缓存控制:http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.9 像这样:
Cache-Control = "Cache-Control" ":" 1#cache-directive
#1cache-directive
语法定义了至少一个缓存指令元素的列表(请参阅此处以了解#values 的正式定义:符号约定和通用语法)
所以,是的,
Cache-Control: no-cache, no-store
相当于(顺序很重要)
缓存控制:无缓存缓存控制:无存储
I have not found any specification about whether duplicate HTTP response headers are allowed by the standard, but I need to know if this will cause compatibility issues.
Say I have a response header like this:
HTTP/1.1 302 Moved Temporarily
Server: Apache-Coyote/1.1
X-Powered-By: Servlet 2.4; JBoss-4.0.3SP1 (build: CVSTag=JBoss_4_0_3_SP1 date=200510231054)/Tomcat-5.5
Cache-Control: no-cache
Cache-Control: no-store
Location: http://localhost:9876/foo.bar
Content-Language: en-US
Content-Length: 0
Date: Mon, 06 Dec 2010 21:18:26 GMT
Notice that there are two Cache-Control
headers with different values. Do browsers always treat them as if they are written like "Cache-Control: no-cache, no-store"?
Yes
HTTP RFC2616 available here says:
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
So, multiple headers with the same name is ok (www-authenticate is such a case) if the entire field-value is defined as a comma-separated list of values.
Cache-control is documented here: http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.9 like this:
Cache-Control = "Cache-Control" ":" 1#cache-directive
The #1cache-directive
syntax defines a list of at least one cache-directive elements (see here for the formal definition of #values: Notational Conventions and Generic Grammar)
So, yes,
Cache-Control: no-cache, no-store
is equivalent to (order is important)
Cache-Control: no-cache
Cache-Control: no-store
这篇关于是否可以接受重复的 HTTP 响应标头?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!