Purging multiple requests

Laurence Rowe l at lrowe.co.uk
Fri Jan 15 15:34:15 CET 2010


2010/1/12 John Norman <john at 7fff.com>:
> Scenario:
>
> -- We would prefer not to leverage checking a lot of paths.
>
> -- Many pages are cached for GET's.
>
> -- In vcl_recv, we want to remove cookies and check the cache:
>
> if (req.request == "GET") {
>     unset req.http.cookie;
>     unset req.http.Authorization;
>     lookup;
>  }
>
> BUT: Suppose the lookup results in a MISS:
>
> Now we would like to "pass" but WITH the cookies. I.e., check the
> cache without cookies; but if there's a miss, reattach them and make
> the request.
>
> ----------------------
>
> Let me put this another way, describing what's happening in our code:
>
> There are many routine server responses for which we have set caching
> headers. All is beautiful.
>
> But we have some, primarily of the form
>
>    /something/edit
>
> where we would like to use the cookie to bring data into a form.
>
> To be sure, we could check the file paths . . .
>
> if (req.request == "GET" && req.url !~ "/edit$") {
>     unset req.http.cookie;
>     unset req.http.Authorization;
>     lookup;
>  }
>
> but we were wondering if there is a pattern to save the cookies and
> then reattach them later (in vcl_miss??), and thus get the "pass" to
> the backend with the cookies back on the request.

You can still lookup even with the authorization and cookie headers,
just make sure you never reach the default vcl_recv by returning
lookup from your vcl_recv. The simplest way to do this is just to copy
and paste in the default and comment out the offending lines:

sub vcl_recv {
    if (req.request != "GET" &&
      req.request != "HEAD" &&
      req.request != "PUT" &&
      req.request != "POST" &&
      req.request != "TRACE" &&
      req.request != "OPTIONS" &&
      req.request != "DELETE") {
        /* Non-RFC2616 or CONNECT which is weird. */
        return (pipe);
    }
    if (req.request != "GET" && req.request != "HEAD") {
        /* We only deal with GET and HEAD by default */
        return (pass);
    }
    #if (req.http.Authorization || req.http.Cookie) {
    #    /* Not cacheable by default */
    #    return (pass);
    #}
    return (lookup);
}

No need to save and restore headers then.

Laurence



More information about the varnish-misc mailing list