Varnish default behaviour is to never lookup for requests containing a Cookie header. In other words, a request containing a Cookie header will never be cached. I need to override this behaviour to just ignore requests with a Cookie header.
Consider the next user behaviour in my application:
- User enters application home page (
/), page should be cached, backend returns apubliccache-control, everything is fine, page gets cached by Varnish. - User navigates to a custom page (
/not-cacheable) which is not cacheable, backend returns aprivatecache-control. Also returns aSet-Cookieheader in the response. Varnish ignores this request and the user ends up with a cookie. So far so good. - User navigates back to the home page (
/), which, remember, is already cached. Problem is, the user request now carries aCookieheader. This causes Varnish to ignore the request and delegate to the backend.
Deleting the Cookie won't work because when the user returns to the /not-cacheable route, he won't see his personalized page, as the Cookie header has been striped out. Instead, the backend returns a newly generated session with a new id in the Set-Cookie.
Also, having every Cookie request to lookup in Varnish caused every request, regarding the method, or the backend response, to be cached.
If there was some way of telling Varnish to just ignore the Cookie header, this way I could cache requests with that header, by letting the backend decide if the request should be cacheable or not.
Any ideas?