跳到主要内容

5.5. Warning

"Warning" header field 用于携带关于 message 状态或 transformation 的附加信息, 这些信息可能没有反映在 status code 中. 这些信息通常用于警告 caching operation 或应用于 message payload 的 transformation 可能引入的不正确性.

warning 可用于其他目的, 包括与 cache 相关和无关的目的. 使用 warning 而不是 error status code, 可以将这些 response 与真正的 failure 区分开.

Warning header field 通常可以应用于任何 message. 但是, 某些 warn-code 特定于 cache, 只能由 cache 在 validation cached entry 时生成.

Warning = 1#warning-value

warning-value = warn-code SP warn-agent SP warn-text
[ SP warn-date ]

warn-code = 3DIGIT
warn-agent = ( uri-host [ ":" port ] ) / pseudonym
; the name or pseudonym of the server adding
; the Warning header field, for use in debugging.
; A pseudonym SHOULD be the generated hostname.
warn-text = quoted-string
warn-date = DQUOTE HTTP-date DQUOTE

一个 response 可以附加多个 warning, 可由 origin server 或 cache 附加, 也可以包含多个 code number 相同但 warn-text 不同的 warning.

收到一个或多个 Warning header field 的 user agent SHOULD 按它们在 response 中出现的顺序, 尽可能多地告知用户这些 warning.

本规范定义下文描述的 warn-code. 位于 http://www.iana.org/assignments/http-warn-codes 的 "Warn Code Registry" 是 warn-code value 及其含义的权威来源.

任何 server 或 cache MAY 在 response 中生成 Warning header field. warning 被分配三位数的 warn-code. 第一位数字表示该 Warning 是否需要在 validation 后从 stored response 中删除:

  • 1xx warn-code 表示描述 response freshness 或 validation status 的 Warning, 因此在 successful validation 后 MUST 删除. 如果执行了 validation, 无论 validation 是否改变 response 的 freshness lifetime, 都 MUST NOT 生成 1xx warn-code.

  • 2xx warn-code 表示描述 representation 某些方面的 Warning, 且这些方面不会由 validation 修正, 例如 representation 的 lossy compression, 因此在 validation 后 MUST NOT 删除, 除非 full response content 发生变化, 即与 response 关联的 entity-tag 发生变化, 在这种情况下 MUST 删除.

当 1xx warn-code 随 stale response 发送时, 每次 cache 发送 stale response 都 SHOULD 发送它, 即使之前已经发送过同一 warning.

当发送 2xx warn-code 时, 每次 cache 发送关联 response 都 SHOULD 发送它, 即使同一 warning 已经发送过.

如果 implementation 发送的 message 带有一个或多个 Warning header, 且其版本为 HTTP/1.0 或更低, 则 sender MUST 在每个 warning-value 中包含与 response 中 Date header field 匹配的 warn-date.

如果 implementation 收到的 message 包含带 warn-date 的 warning-value, 且该 warn-date 与 response 中的 Date value 不同, 则在存储, 转发或使用该 message 之前, MUST 从 message 中删除该 warning-value. 这可以防止朴素缓存 Warning header field 带来的不良后果.

如果所有 warning-value 都因此被删除, Warning header field 也 MUST 被删除.