gpt4 book ai didi

HTTP 过期 header 值 "0"和 "-1"

转载 作者:可可西里 更新时间:2023-11-01 15:03:55 26 4
gpt4 key购买 nike

HTTP 响应 header 中的Expires: 0Expires: -1 有什么区别? RFC 2616定义无效的日期格式,特别是将值“0” 定义为已经过期。然而,一些服务器(例如 www.google.de )回复 Expires: -1

与使用 -1 相比使用 0 是否有优势,或者对于某些损坏的 HTTP 客户端是否需要这样做?

最佳答案

问题在于 Internet Explorer(尤其是旧版本)如何处理无效的 Expires header 。IE 使用 Trident布局引擎和WinINET处理 HTTP 请求的 API。你可能知道 Expires 可以在 HTTP header 中指定

Expires: 0

或在元标记中

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

在第二种情况下,Expires 成为响应内容的一部分(不是标题内容),因此它将是 processed by Trident and then propagated to WinINET :

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.

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

关于HTTP 过期 header 值 "0"和 "-1",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11357430/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com