4.1. 304 Not Modified

3 阅读1分钟

4.1. 304 Not Modified

4.1. 304 Not Modified

返回304时如何携带Header

必须携带的Header+可以携带的用于指导缓存的Header

必须(MUST)携带的Header

// MUST
 The server generating a 304 response MUST generate any of the
   following header fields that would have been sent in a 200 (OK)
   response to the same request: Cache-Control, Content-Location, Date,
   ETag, Expires, and Vary.
  • 上述列表中的header fields,如果在给request返回200时,返回了,则当给这个request返回304时也要(MUST)返回。

可以携带用于指导缓存更新的Header

// SHOULD NOT   
  Since the goal of a 304 response is to minimize information transfer
   when the recipient already has one or more cached representations, a
   sender SHOULD NOT generate representation metadata other than the
   above listed fields unless said metadata exists for the purpose of
   guiding cache updates (e.g., Last-Modified might be useful if the
   response does not have an ETag field).   

上述节选定义了返回304时,如何返回metadata:

  • sender不应该(SHOULD NOT)发送上述列表以外的metadata,除非它能帮助提升缓存更新(例如发送Last-Modified当ETag生成失败时)
  Requirements on a cache that receives a 304 response are defined in
   Section 4.3.4 of [RFC7234].  If the conditional request originated
   with an outbound client, such as a user agent with its own cache
   sending a conditional GET to a shared proxy, then the proxy SHOULD
   forward the 304 response to that client.

返回304时如何携带body

304 response不能携带body。gemini说这里的"cannot"语义等同于"MUST NOT"