简体   繁体   English

为什么不Vary:Cookie在服务工作者中工作?

[英]Why doesn't Vary: Cookie work in a service worker?

In my app, I set a cookie and then call fetch('/foo', {credentials: 'same-origin'}) . 在我的应用程序中,我设置了一个cookie,然后调用fetch('/foo', {credentials: 'same-origin'}) This is intercepted in the service worker which uses caches to cache the request and response. 这是在服务工作者中截获的,它使用caches来缓存请求和响应。 The response has Vary: Cookie set. 响应有Vary: Cookie设置。 Then, I change the cookie and call fetch again as above. 然后,我更改cookie并再次调用fetch ,如上所述。 But when I call caches.match in the service worker, the old request is matched! 但是当我在服务工作者中调用caches.match时,旧的请求是匹配的! Why is this happening? 为什么会这样? Can I fix it? 我可以修理吗?

I cannot comment (low rep) so I am posting here. 我不能评论(低代表)所以我在这里发帖。

Service workers cannot intercept the cookies. 服务人员无法拦截cookie。 There is a proposed new api in development . 有一个拟议的新api正在开发中
Why don't you try to set a custom header for your requests depending on the content of the cookie. 为什么不尝试根据cookie的内容为您的请求设置自定义标头。

Request 1: 要求1:
X-Cookie-Value: 1 X-Cookie-Value:1
Vary: X-Cookie-Value 变化:X-Cookie-Value

Request 2: 要求2:
X-Cookie-Value: 2 X-Cookie-Value:2
Vary: X-Cookie-Value 变化:X-Cookie-Value

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM