If-Modified-Since 与 If-None-Match

If-Modified-Since 与 If-None-Match

通常浏览器的条件请求是这样的:

获取/i/yahoo.gif

HTTP/1.1 主机:us.yimg.com

如果修改时间:2006 年 12 月 12 日星期二 03:03:59 GMT

如果没有匹配:“10c24bc-4ab-457e1c1f” HTTP/1.1

但是 If-Modified-Since 和 If-None-Match 之间有什么关系呢?是或吗?是和吗?所以如果其中任何一个“失败”,就会发送新版本吗?

答案1

http://www.ietf.org/rfc/rfc2616.txt

13.3.4 何时使用实体标签和上次修改日期的规则

  • HTTP/1.1 原始服务器在收到包含 Last-Modified 日期(例如,在 If-Modified-Since 或 If-Unmodified-Since 标头字段中)和一个或多个实体标签(例如,在 If-Match、If-None-Match 或 If-Range 标头字段中)作为缓存验证器的条件请求时,不得返回 304(未修改)的响应状态,除非这样做与请求中的所有条件标头字段一致。

  • HTTP/1.1 缓存代理在收到包含 Last-Modified 日期和一个或多个实体标签作为缓存验证器的条件请求时,不得向客户端返回本地缓存的响应,除非该缓存响应与请求中的所有条件标头字段一致。

    • 注意:这些规则背后的一般原则是,HTTP/1.1 服务器和客户端应在其响应和请求中传输尽可能多的非冗余信息。接收此信息的 HTTP/1.1 系统将对其收到的验证器做出最保守的假设。

答案2

请注意,较新的“RFC 7232 超文本传输​​协议 (HTTP/1.1):条件请求”有一节关于优先权这改变了指定此行为的方式。这实际上表示If-None-Match优先于If-Modified-Since。请参阅:

   3.  When If-None-Match is present, evaluate the If-None-Match
       precondition:

       *  if true, continue to step 5

       *  if false for GET/HEAD, respond 304 (Not Modified)

       *  if false for other methods, respond 412 (Precondition Failed)

   4.  When the method is GET or HEAD, If-None-Match is not present, and
       If-Modified-Since is present, evaluate the If-Modified-Since
       precondition:

       *  if true, continue to step 5

       *  if false, respond 304 (Not Modified)

   5.  When the method is GET and both Range and If-Range are present,
       evaluate the If-Range precondition:

       *  if the validator matches and the Range specification is
          applicable to the selected representation, respond 206
          (Partial Content) [RFC7233]

   6.  Otherwise,

       *  all conditions are met, so perform the requested action and
          respond according to its success or failure.

在这里查看步骤 3 如何导致对先决条件的评估If-None-Match,如果先决条件存在,则您永远不会转到步骤 4,即评估的步骤If-Modified-Since

相关内容