有人知道一旦用户通过重新加载页面成功登录,reddit 是如何设法绕过 cloudflare 静态 html 缓存的吗?
我看到成功登录后重新加载了当前页面。
登录前的响应头:
CF-Cache-Status: HIT
CF-RAY: 23b76b8270950e30-MXP
Cache-Control: max-age=0, must-revalidate
Content-Encoding: gzip
Content-Length: 20794
Content-Type: text/html; charset=UTF-8
Date: Mon, 26 Oct 2015 16:08:27 GMT
Server: cloudflare-nginx
Vary: Accept-Encoding
X-Firefox-Spdy: 3.1
X-Frame-Options: SAMEORIGIN
strict-transport-security: max-age=15552000; includeSubDomains; preload
x-content-type-options: nosniff
x-moose: majestic
x-ua-compatible: IE=edge
x-xss-protection: 1; mode=block
Run Code Online (Sandbox Code Playgroud)
登录后的响应头:
CF-RAY: 23b76cb065140e30-MXP
Cache-Control: private, s-maxage=0, max-age=0, must-revalidate, max-age=0, must-revalidate
Content-Encoding: gzip
Content-Length: 18697
Content-Type: text/html; charset=UTF-8
Date: Mon, 26 Oct 2015 16:09:16 GMT
Expires: -1
Server: cloudflare-nginx
Vary: accept-encoding
X-Firefox-Spdy: 3.1
X-Frame-Options: SAMEORIGIN
strict-transport-security: max-age=15552000; includeSubDomains; preload
x-content-type-options: nosniff
x-moose: majestic
x-ua-compatible: IE=edge
x-xss-protection: 1; mode=block
Run Code Online (Sandbox Code Playgroud)
感谢您的任何提示。
使用 CloudFlare 有两种关键方法可以做到这一点:
CloudFlare 的帮助中心解释了如何通过从源发送的标头来控制缓存:
更改 CloudFlare 将缓存的内容的第二种方法是通过缓存从源发送的标头。CloudFlare 将遵守这些设置(但仅适用于具有我们默认缓存的扩展名的文件),除非页面规则设置为缓存所有内容并且边缘缓存过期 TTL 设置。以下是我们考虑的缓存标头:
- 如果 Cache-Control 标头设置为“private”、“no-store”、“no-cache”或“max-age=0”,或者响应中有 cookie,则 CloudFlare 不会缓存资源。
- 否则,如果 Cache-Control 标头设置为“public”并且“max-age”大于 0,或者如果将来任何时候设置了 Expires 标头,我们将缓存资源。
注意:根据 RFC 规则,“Cache-Control: max-age”胜过“Expires”标头。如果我们看到两者并且他们不同意,则 max-age 获胜。
在 PHP 中,您可以使用 header 函数实现这一点,如下所示:
header("Cache-Control: no-cache, must-revalidate");
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
8845 次 |
| 最近记录: |