HTTP Expires头值“0”。和“-1” [英] HTTP Expires header values "0" and "-1"

查看:4270
本文介绍了HTTP Expires头值“0”。和“-1”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

HTTP响应标头中 Expires:0 Expires:-1 之间有什么区别? RFC 2616 定义无效的日期格式,尤其包括值0 已过期。但是,某些服务器(例如www.google.de)回复 Expires:-1

What is the difference between Expires: 0 and Expires: -1 in the HTTP response header? RFC 2616 defines invalid date formats, especially including the value "0" as already expired. However, some servers (e.g. www.google.de) reply with Expires: -1.

是否有使用 -1 而不是 0 的优势还是某些损坏的HTTP客户端甚至需要它?

Is there an advantage over using -1 over 0 or is this even required for some broken HTTP clients?

推荐答案

问题在于Internet Explorer(尤其是旧版本)处理的Expires标头的无效程度。
IE使用 Trident 布局引擎和 WinINET 用于处理HTTP请求的API。您可能知道可以在HTTP标头中指定过期

The problem is in how invalid Expires header processed by Internet Explorer (especially older versions). IE uses Trident layout engine and WinINET API to process HTTP requests. As you may know Expires could be specified in HTTP header

Expires: 0

或元标记

<meta http-equiv="Expires" content="0">

在第二种情况下,Expires成为响应内容的一部分(不是标题内容),因此它将成为由Trident处理,然后传播到WinINET

In second case, Expires became part of the response content (not header content), so it will be processed by Trident and then propagated to WinINET:


如果WinINET下载带有无效Expires标头的响应(例如
一个不包含有效的HTTPDATE值)并且没有其他缓存
指令,它会将文档标记为在一小时前过期。
然而,Trident没有这样的逻辑。如果指定了无效时间,
Trident将获取当前时间戳并将其用作到期时间。
如果遇到
Pragma:no-cache指令,Trident也将使用当前时间戳。如果用户尝试在HTTP / 404处理
的同一秒内重新导航到
当前文档,则现有缓存
条目的错误更新到期将导致它被视为新鲜的请求。如果
用户点击刷新按钮或F5,则会绕过缓存并显示404页面

If WinINET downloads a response with an invalid Expires header (e.g. one that doesn’t contain a valid HTTPDATE value) and no other caching directives, it will mark the document as having expired one hour ago. Trident, however, has no such logic. If you specify an invalid time, Trident grabs the current timestamp and uses that as the expiration. Trident will also use the current timestamp if it encounters the Pragma: no-cache directive. If the user tries to re-navigate to the current document during same exact second that the HTTP/404 was processed, the incorrectly-updated expiration of the existing cache entry will result in it being treated as fresh for that request. If the user hit the Refresh button or F5, the cache would be bypassed and the 404 page would be shown.

换句话说过期:0 并不总是导致资源过期,因此应该避免并且过期:[某个有效日期在应该使用过去的

In other words Expires: 0 not always leads to immediate resource expiration, therefore should be avoided and Expires: [some valid date in the past] should be used instead.

这篇关于HTTP Expires头值“0”。和“-1”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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