Restoring cookies on a miss
Ken Brownfield
kb+varnish at slide.com
Mon Jan 25 23:42:14 CET 2010
If you sometimes see the proper cookies being passed to the back-end, I would think this would be a client problem? The VCL logic in question should either always work or never work.
I just did a test of this, and I see the proper header hitting the back-end. Maybe you're seeing unexpectedly cookie-less requests?
--
Ken
On Jan 25, 2010, at 1:03 PM, John Norman wrote:
> Folks,
>
> I've been trying to implement a technique posted here to restore
> cookies on a cache miss.
>
> The original question is here:
>
> http://projects.linpro.no/pipermail/varnish-misc/2010-January/003505.html
>
> and an interesting answer is here:
>
> http://projects.linpro.no/pipermail/varnish-misc/2010-January/003506.html
>
> Below is my .vcl file.
>
> And again, here's the use case:
>
> We have certain pages that should never be cached. The user comes in
> with cookies set: "session=foo" or some such.
>
> We strip the cookie and do a lookup.
>
> If there's a hit, return what is in the cache.
>
> If there's a miss, we'd like to fetch with the cookie.
>
> Then, in fetch, pass for pages set for no-cache, and deliver for those
> that are public.
>
> It can be assumed that these pages are never hit first by non-cookied users.
>
> But -- I am seeing a lot of requests that have no cookies on the backend.
>
> John
>
> Here's the VCL:
>
> backend reviews0 {
> .host = "127.0.0.1";
> .port = "7000";
> }
>
> backend reviews1 {
> .host = "127.0.0.1";
> .port = "7001";
> }
>
> director reviews round-robin {
> { .backend = reviews0; }
> { .backend = reviews1; }
> }
>
> sub vcl_recv {
>
> unset req.http.user-agent;
>
> set req.backend = reviews;
>
> if (req.request != "GET" && req.request != "HEAD") {
> pass;
> }
>
> set req.http.OLD-Cookie = req.http.Cookie;
> unset req.http.cookie;
>
> lookup;
> }
>
> sub vcl_miss {
> if (req.http.OLD-Cookie) {
> set bereq.http.Cookie = req.http.OLD-Cookie;
> unset req.http.OLD-Cookie;
> }
> fetch;
> }
>
> sub vcl_fetch {
>
> unset obj.http.user-agent;
>
> if (obj.http.Pragma ~ "no-cache" ||
> obj.http.Cache-Control ~ "no-cache" ||
> obj.http.Cache-Control ~ "private") {
> pass;
> }
>
> if (obj.http.Cache-Control ~ "public") {
> unset obj.http.Set-Cookie;
> deliver;
> }
> pass;
> }
> _______________________________________________
> varnish-misc mailing list
> varnish-misc at projects.linpro.no
> http://projects.linpro.no/mailman/listinfo/varnish-misc
More information about the varnish-misc
mailing list