- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我的客户端在向我的服务器发出无害请求后被注销。我控制了两端,经过大量调试,我发现发生了以下情况:
304 Not Modified
,不带任何授权 header 。据我所知,the browser must not cache any request containing Authorization 。尽管如此,
chrome://view-http-cache/http://localhost:10080/api/SearchHost
显示
HTTP/1.1 200 OK
Date: Thu, 23 Nov 2017 23:50:16 GMT
Vary: origin, accept-encoding, authorization, x-role
Cache-Control: must-revalidate
Server: 171123_073418-d8d7cb0 =
x-delay-seconds: 3
Authorization: Wl6pPirDLQqWqYv
Expires: Thu, 01 Jan 1970 00:00:00 GMT
ETag: "zUxy1pv3CQ3IYTFlBg3Z3vYovg3zSw2L"
Content-Encoding: gzip
Content-Type: application/json;charset=utf-8
Content-Length: 255
有趣的服务器 header 用一些内部信息替换了 Jetty 服务器 header (出于安全原因不应提供服务) - 忽略它。 curl 是这样说的:
< HTTP/1.1 304 Not Modified
< Date: Thu, 23 Nov 2017 23:58:18 GMT
< Vary: origin, accept-encoding, authorization, x-role
< Cache-Control: must-revalidate
< Server: 171123_073418-d8d7cb0 =
< ETag: "zUxy1pv3CQ3IYTFlBg3Z3vYovg3zSw2L"
< x-delay-seconds: 3
< Content-Encoding: gzip
这也发生在 Firefox 中,尽管我目前无法重现它。 The RFC继续,看起来上面链接的答案并不准确:
unless a cache directive that allows such responses to be stored is present in the response
看起来响应是可缓存的。没关系,我确实希望内容被缓存,但我不希望从缓存中提供授权 header 。这可能吗?
我的服务器过去仅在响应登录请求时才发送Authorization
header 。这曾经工作得很好,新的要求带来了问题。
我们的网站允许用户任意长时间地保持登录状态(我们不做敏感业务)。我们正在更改授权 token 的格式,并且我们不想因此强制所有用户重新登录。因此,我让服务器在看到过时但有效的授权 token 时发送更新的授权 token 。因此,现在任何响应都可能包含授权 token ,但大多数响应都不包含。
浏览器缓存将仍然有效的响应与过时的授权 token 相结合。
作为解决方法,我让服务器在存在授权 token 时不发送 etag
。它有效,但我更喜欢一些更干净的解决方案。
最佳答案
链接答案中的引用具有误导性,因为它省略了一个重要部分:“如果缓存是共享的”。这是正确的引用( RFC7234 Section 3 ):
A cache MUST NOT store a response to any request, unless: ... the Authorization header field (see Section 4.2 of [RFC7235]) does not appear in the request, if the cache is shared,
RFC 的这一部分基本上是一个摘要。这是完整的规则 ( RFC7234 Section 3.2 ),本质上讲的是同一件事:
A shared cache MUST NOT use a cached response to a request with an Authorization header field (Section 4.2 of [RFC7235]) to satisfy any subsequent request unless a cache directive that allows such responses to be stored is present in the response.
浏览器缓存是共享缓存吗?Introduction section of the RFC对此进行了解释。 :
A private cache, in contrast, is dedicated to a single user; often, they are deployed as a component of a user agent.
这意味着浏览器缓存是私有(private)缓存。它不是共享缓存,因此上述规则不适用,这意味着 Chrome 和 Firefox 都能正确执行其工作。
现在是解决方案。
该规范建议可以在没有授权 header 的情况下重用包含授权的缓存响应。不幸的是,它还表示该功能尚未广泛实现。
因此,我能想到的最简单也是最面向 future 的解决方案是确保不缓存任何包含授权 token 的响应。例如,每当服务器看到已过时但有效的授权 token 时,请发送一个新的有效 token 以及 Cache-Control: no-store
禁止缓存。
此外,您绝不能发送带有授权 header 的 Cache-Control: Must-revalidate
,因为 must-revalidate
指令实际上允许缓存响应,包括通过共享缓存这可能会在未来造成更多问题。
... unless a cache directive that allows such responses to be stored is present in the response.
In this specification, the following Cache-Control response directives (Section 5.2.2) have such an effect: must-revalidate, public, and s-maxage.
关于caching - 浏览器从缓存中提供过时的授权 header ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47464893/
我阅读了有关 JSR 107 缓存 (JCache) 的内容。 我很困惑:据我所知,每个 CPU 都管理其缓存内存(无需操作系统的任何帮助)。 那么,为什么我们需要 Java 缓存处理程序? (如果C
好吧,我是 jQuery 的新手。我一直在这里和那里搞乱一点点并习惯它。我终于明白了(它并不像某些人想象的那么难)。因此,鉴于此链接:http://jqueryui.com/sortable/#dis
我正在使用 Struts 2 和 Hibernate。我有一个简单的表,其中包含一个日期字段,用于存储有关何时发生特定操作的信息。这个日期值显示在我的 jsp 中。 我遇到的问题是hibernate更
我有点不确定这里发生了什么,但是我试图解释正在发生的事情,也许一旦我弄清楚我到底在问什么,就可能写一个更好的问题。 我刚刚安装了Varnish,对于我的请求时间来说似乎很棒。这是一个Magneto 2
解决 Project Euler 的问题后,我在论坛中发现了以下 Haskell 代码: fillRow115 minLength = cache where cache = ((map fill
我正试图找到一种方法来为我网络上的每台计算机缓存或存储某些 python 包。我看过以下解决方案: pypicache但它不再被积极开发,作者推荐 devpi,请参见此处:https://bitbuc
我想到的一个问题是可以从一开始就缓存网络套接字吗?在我的拓扑中,我在通过双 ISP 连接连接到互联网的 HAProxy 服务器后面有 2 个 Apache 服务器(带有 Google PageSpee
我很难说出不同缓存区域 (OS) 之间的区别。我想简要解释一下磁盘\缓冲区\交换\页面缓存。他们住在哪里?它们之间的主要区别是什么? 据我了解,页面缓存是主内存的一部分,用于存储从 I/O 设备获取的
1.题目 请你为最不经常使用(LFU)缓存算法设计并实现数据结构。 实现 LFUCache 类: LFUCache(int capacity) - 用数据结构的容量 capacity 初始化对象 in
1.题目 请你设计并实现一个满足 LRU (最近最少使用) 缓存 约束的数据结构。 实现 LRUCache 类: ① LRUCache(int capacity) 以正整数作为容量 capacity
我想在访问该 View 时关闭某些页面的缓存。它适用于简单查询模型对象的页面。 好像什么时候 'django.middleware.cache.FetchFromCacheMiddleware', 启
documents为 ExePackage element state Cache属性的目的是 Whether to cache the package. The default is "yes".
我知道 docker 用图层存储每个图像。如果我在一台开发服务器上有多个用户,并且每个人都在运行相同的 Dockerfile,但将镜像存储为 user1_myapp . user2 将其存储为 use
在 Codeigniter 中没有出现缓存问题几年后,我发现了一个问题。我在其他地方看到过该问题,但没有适合我的解决方案。 例如,如果我在 View 中更改一些纯 html 文本并上传新文件并按 F5
我在 Janusgraph 文档中阅读了有关 Janusgraph Cache 的内容。关于事务缓存,我几乎没有怀疑。我在我的应用程序中使用嵌入式 janusgrah 服务器。 如果我只对例如进行读取
我想知道是否有来自终端的任何命令可以用来匹配 Android Studio 中执行文件>使缓存无效/重新启动的使用。 谢谢! 最佳答案 According to a JetBrains employe
我想制作一个 python 装饰器来内存函数。例如,如果 @memoization_decorator def add(a, b, negative=False): print "Com
我经常在 jQuery 事件处理程序中使用 $(this) 并且从不缓存它。如果我愿意的话 var $this = $(this); 并且将使用变量而不是构造函数,我的代码会获得任何显着的额外性能吗?
是的,我要说实话,我不知道varnish vcl,我可以解决一些基本问题,但是我不太清楚,这就是为什么我遇到问题了。 我正在尝试通过http请求设置缓存禁止,但是该请求不能通过DNS而是通过 Varn
在 WP 站点上加载约 4000 个并发用户时遇到此问题。 这是我的配置: F5 负载均衡器 ---> Varnish 4,8 核,32 Gb RAM ---> 9 个后端,4 个核,每个 16 RA
我是一名优秀的程序员,十分优秀!