HTTP If-None-Match 与 If-Match

发布于 2024-08-19 16:19:14 字数 772 浏览 5 评论 0原文

我目前正在构建一个 PHP 脚本,它将在需要时回答 HTTP“304 Not Modified”。

(请参阅问题#2086712< /a> 到目前为止我所做的)。

目前我回答以下问题:

  • If-Modified-Since
  • If-None-Match

但我发现另外 3 个标头可以触发“条件 GET”(参见 http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html#sec9.3):

  • 如果- Match
  • If-Unmodified-Since
  • If-Range

最后两个似乎与我的缓存系统无关(它们似乎在恢复“大”下载时使用),但我还没有发现“If-Match”是否可以在我的系统中使用。

“If-Match”是否在代理或 Web 浏览器中用于“常规”页面内容? “If-Match”与“If-None-Match”有何不同?

我应该支持这三个还是只支持其中的一部分?欢迎任何帮助!

I'm currently building up a PHP script that will answer HTTP "304 Not Modified" when required.

(See question #2086712 for what I do so far).

Currently I answer to the following:

  • If-Modified-Since
  • If-None-Match

But I found out that 3 more headers can trigger a "conditional GET" (See http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html#sec9.3):

  • If-Match
  • If-Unmodified-Since
  • If-Range

The last 2 seems irrevelent to my caching system (they seem to be used when resuming "big" downloads) but I haven't found if "If-Match" could be of use in my system.

Does "If-Match" is used in proxies or Web browser for "regular" page content? How "If-Match" is different than "If-None-Match"?

Should I support those 3 or just some of them? Any help welcome!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

南渊 2024-08-26 16:19:14

If-Match

服务器必须返回 412(前提条件失败)响应,如果:

  • 没有实体标签匹配,
  • 或者给出“*”并且当前实体不存在

,则应忽略 If-Match

  • 如果:任何实体标签匹配
  • 或者如果请求结果不是 2xx 或 412 状态(没有 If-Match)
  • ,或者如果给出“*”并且资源存在任何当前实体关于

if-match 的结论:

  • 含义“If-Match: *”的意思是如果源服务器选择的表示形式...存在则应执行该方法,如果表示不存在则不得执行。

RFC2616 中的 If-Match

If-Unmodified-Since

服务器必须返回 412(先决条件失败)响应,如果:

  • 请求的变体自指定时间以来已被修改

,则应忽略 If-Unmodified-Since

  • 字段中指定的时间以来请求的资源没有被修改
  • 如果自该 正常请求(即没有 If-Unmodified-Since 标头)将导致 2xx 或 412 状态以外的任何结果
  • ,或者指定的日期无效

RFC2616 中的 If-Unmodified-Since

If-Range

非正式地,其含义是“如果实体未更改,请将我缺少的部分发送给我;”否则,请将整个新实体发送给我'

先决条件:

  • If-Range 标头应该仅与Range 标头一起使用,并且如果请求不包含 Range 标头,或者服务器包含,则必须忽略不支持子范围操作。

如果 If-Range 标头与实体的当前实体标签匹配,服务器应该提供 206(部分内容)响应。否则,服务器应该使用 200(OK)响应返回整个实体。

RFC2616 中的 If-Range

未定义结果

具有以下内容标头组合会导致未定义的结果:

  • If-Modified-Since and If-Match
  • If-Modified-Since and If-Unmodified-Since
  • If-None-Match and If-Match
  • If-None-Match and If-Unmodified-Since

这些规则已由以下规则分解(可以在RFC2616):

  • If-Match ( If-None-Match If-Modified-Since )
  • If-Modified-Since ( If-Match If-Unmodified-Since )
  • If-None-Match ( If-Match If-Unmodified-Since )
  • If-Unmodified-Since ( If-None-Match If-Modified-Since )

更新的 RFC 7232 取代了 2616。

If-Match

The server MUST return a 412 (Precondition Failed) response, if:

  • none of the entity tags match,
  • or "*" is given and no current entity exists

If-Match should be ignored, if:

  • any of the entity tags match
  • or if the request results in anything other than a 2xx or 412 status (without If-Match)
  • or if "*" is given and any current entity exists for the resource

Conclusion on if-match:

  • The meaning of "If-Match: *" is that the method should be performed if the representation selected by the origin server ... exists, and must not be performed if the representation does not exist.

If-Match in RFC2616

If-Unmodified-Since

The server MUST return a 412 (Precondition Failed) response, if:

  • the requested variant has been modified since the specified time

If-Unmodified-Since should be ignored, if

  • the requested resource has not been modified since the time specified in this field
  • or the request normally (i.e., without the If-Unmodified-Since header) would result in anything other than a 2xx or 412 status
  • or the specified date is invalid

If-Unmodified-Since in RFC2616

If-Range

Informally, its meaning is 'if the entity is unchanged, send me the part(s) that I am missing; otherwise, send me the entire new entity'

Preconditions:

  • The If-Range header SHOULD only be used together with a Range header, and MUST be ignored if the request does not include a Range header, or if the server does not support the sub-range operation.

Server SHOULD provide 206 (Partial content) response, if If-Range header matches the current entity tag for the entity. Otherwise, server SHOULD return the entire entity using a 200 (OK) response.

If-Range in RFC2616

Undefined results

Having the following combination of headers leads to an undefined result:

  • If-Modified-Since and If-Match
  • If-Modified-Since and If-Unmodified-Since
  • If-None-Match and If-Match
  • If-None-Match and If-Unmodified-Since

These rules have been decomposed from the following ones (can be found in RFC2616):

  • If-Match and ( If-None-Match or If-Modified-Since )
  • If-Modified-Since and ( If-Match or If-Unmodified-Since )
  • If-None-Match and ( If-Match or If-Unmodified-Since )
  • If-Unmodified-Since and ( If-None-Match or If-Modified-Since )

A more recent RFC 7232 superseded 2616.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文