(弱)ETag和最后修改 [英] (Weak) ETags and Last-Modified

查看:401
本文介绍了(弱)ETag和最后修改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

据我了解,规范,RFC 2616(HTTP/1.1)中引入的ETag是Last-Modified-Header的后继(某种形式),提议将其提供给软件架构师更多控制缓存重新验证过程.

As far as I understand the specs, the ETag, which was introduced in RFC 2616 (HTTP/1.1) is a successor (of sorts) for the Last-Modified-Header, which is proposet to give the software-architect more controll over the cache-revalidating process.

如果同时存在两个缓存验证标头(If-None-Match和If-Modified-Since),则根据RFC 2616,客户端(即浏览器)在检查资源是否已更改时应使用ETag. .根据RFC 2616的14.26节,如果If-None-Match-Header中显示的ETag已更改,并且服务器必须忽略其他If-Modified-Since-Header,则服务器不得以304 Not Modified进行响应. (如果存在).如果显示的ETag匹配,则他不得执行请求,除非Last-Modified-Header中的Date如此. (如果显示的ETag匹配,则服务器应以304未修改的形式响应,以获取GET或HEAD请求...)

If both Cache-Validation-Headers (If-None-Match and If-Modified-Since) are present, according to RFC 2616, the client (i.e. the browser) should use the ETag when checking, if a resource has changed. According to section 14.26 of RFC 2616, the server MUST NOT respond with a 304 Not Modified, if the ETag presented in a If-None-Match-Header has changed, and the server has to ignore an additional If-Modified-Since-Header, if present. If the presented ETag matches, he MUST NOT perform the request, unless the Date in the Last-Modified-Header says so. (If the presented ETag matches, the server should respond with a 304 Not Modified in case of a GET- or HEAD-request...)

本节为一些猜测留有余地:

This section leaves room for some speculations:

  • 强大的ETag应该每次"更改,资源也会更改.因此,必须用其他响应(如304 Not Modified)响应具有不变的ETag和不匹配的If-Modified-Since-Header的请求,这有点矛盾,因为强ETag表示资源是没有修改. (不过,这并不是致命的,因为服务器可以再次发送相同的不变资源.)
  • ...

...好 在我写这篇文章的时候,这个问题一直困扰着这个答案:

... o.k. While I was writing this, the question was boiling down to this answer:

上述(小的)矛盾是由于ETag弱而造成的.标有弱ETag的资源可能已更改,尽管ETag并未更改.因此,如果ETag较弱,那么当ETag尚未更改但If-Modified-Since中显示的日期不匹配时,用304 Not Modified回答是错误的吗?

The (small) contradiction stated above, was made because of Weak ETags. A resource marked with a Weak ETag may have changed, although the ETag has not. So, in case of a Weak ETag it would be wrong, to answer with 304 Not Modified, when the ETag has not changed, but the date presented in the If-Modified-Since does not match, right?

推荐答案

常规(强)ETag和弱ETag之间的区别在于,匹配的强ETag保证文件是逐字节相同的,而匹配的则是ETag弱表示内容在语义上是相同的.因此,如果文件内容更改,则弱ETag也应更改.

The difference between a regular (strong) ETag and a weak ETag is that a matching strong ETag guarantees the file is byte-for-byte identical, whereas a matching weak ETag indicates that the content is semantically the same. So if the content of the file changes, the weak ETag should change as well.

在您呈现的情况下,服务器上的文件可能比客户端中的缓存副本新-但由于ETag匹配,因此从语义上讲等效于缓存副本,因此返回304响应是可以接受的

In the scenario you present, the file on the server may be newer than the cached copy in the client -- but since the ETag matches, it is semantically equivalent to the cached copy so it would be acceptable to return a 304 response.

这篇关于(弱)ETag和最后修改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆