Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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'}). This is intercepted in the service worker which uses caches to cache the request and response. The response has Vary: Cookie set. Then, I change the cookie and call fetch again as above. But when I call caches.match in the service worker, the old request is matched! Why is this happening? Can I fix it?

like image 619
Dan Avatar asked May 08 '17 10:05

Dan


1 Answers

I cannot comment (low rep) so I am posting here.

Service workers cannot intercept the cookies. There is a proposed new api in development .
Why don't you try to set a custom header for your requests depending on the content of the cookie.

Request 1:
X-Cookie-Value: 1
Vary: X-Cookie-Value

Request 2:
X-Cookie-Value: 2
Vary: X-Cookie-Value

like image 200
ignatisD Avatar answered Nov 13 '22 10:11

ignatisD