是否可以接受重复的HTTP响应标头?

时间:2010-12-06 21:54:36

标签: http-headers

我没有找到关于标准是否允许重复HTTP响应标头的任何规范,但我需要知道这是否会导致兼容性问题。

说我有这样的响应标题:

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

请注意,有两个Cache-Control标头具有不同的值。浏览器是否总是将它们视为“Cache-Control:no-cache,no-store”?

2 个答案:

答案 0 :(得分:128)

HTTP RFC2616可用here说:

  

可能存在具有相同字段名称的多个消息头字段   在消息中,当且仅当该标头的整个字段值   字段被定义为以逗号分隔的列表[即,#(值)]。它必须   可以将多个标题字段合并为一个   “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语法定义了至少一个cache-directive元素的列表(请参阅此处了解#values的正式定义:Notational Conventions and Generic Grammar

所以,是的,

Cache-Control: no-cache, no-store

相当于(订单很重要)

Cache-Control: no-cache
Cache-Control: no-store

答案 1 :(得分:0)

请注意,HSTS RFC6797通过定义STS标头的多个实例的行为来与RFC2616(违反了“ if and only if”语言)相矛盾,尽管它没有填充逗号分隔的值:

  "If a UA receives more than one STS header field in an HTTP
  response message over secure transport, then the UA MUST process
  only the first such header field."
相关问题