跳到主要内容

4.3.3. 处理验证响应 (Handling a Validation Response)

cache 对 conditional request 的 response 的处理取决于其 status code:

  • 304 (Not Modified) response status code 表示 stored response 可以被更新和重用; 见 Section 4.3.4.
  • full response, 即带有 payload body 的 response, 表示 conditional request 中指定的 stored response 都不合适. cache MUST 改用 full response 来满足 request. cache MAY 存储此类 response, 但需要遵守其约束 (见 Section 3).
  • 但是, 如果 cache 在尝试 validation 某个 response 时收到 5xx (Server Error) response, 它可以将此 response 转发给 requesting client, 或者表现得像 server 未能响应一样. 在后一种情况下, cache MAY 发送先前 stored response (见 Section 4.2.4).

4.3.4. 验证时刷新存储响应 (Freshening Stored Responses upon Validation)

当 cache 收到 304 (Not Modified) response 时, 它 MUST 按 RFC 7232 Section 4.1 使用 304 response 中提供的 header field 更新 stored response 的 header field.

cache 还 MUST 使用更新后的 stored response 来满足触发 validation 的 request, 并且 MAY 使用它来满足其他 request.

更新 header field value 时, cache MUST 删除 stored response 中 warn-code 为 1xx 的任何 Warning header field (见 Section 5.5), 并且 MUST 将 304 response 中的任何 Warning header field 添加到更新后的 stored response.

4.3.5. 通过 HEAD 刷新响应 (Freshening Responses via HEAD)

对 HEAD method 的 response 与使用 GET 发出的等价 request 所得到的 response 相同, 只是缺少 body. HEAD response 的这一特性允许 cache 在不传输整个 response content 的情况下更新 stored response. 因此, 如果 HEAD response 具有与 stored GET response 匹配的 Last-Modified 和/或 ETag field value, cache MAY 使用 HEAD response 更新 cached GET response.

使用 HEAD response 更新 stored response 时, cache MUST 使用 HEAD response 中提供的 header field value 更新 stored response 的 header field.

4.4. 失效 (Invalidation)

cache invalidation 的目的是消除实际 response value, 即非 header field 部分, 很可能与被 invalidated response 显著不同的 response, 从而避免两者被作为替代项呈现时造成混淆.

当 cache 收到 method 可能导致 stored response 更新的 request 时, 例如 PUT, POST 或 DELETE (见 [RFC7231] Section 4.2.1), 它 MUST 将 effective request URI ([RFC7230] Section 5.5) 的所有 stored response 视为 invalidated, 并且也将 Location 和 Content-Location response header field 中 URI 的 stored response 视为 invalidated, 如果这些 field 存在.

但是, 如果 response status code 是 redirect, 且 Location 或 Content-Location response header field 中出现的 URI 的 host component 与 effective request URI 的 host 不同, cache MUST NOT invalidate 该 URI.

当 cache 收到对某个 method 的 request 的 non-error response, 且该 method 的语义暗示 target resource 的状态可能已经被改变, 例如 PUT, POST, DELETE 和 PATCH, cache MUST invalidate effective request URI ([RFC7230] Section 5.5).