Return Lookup

Hugo Cisneiros (Eitch) hugo.cisneiros at gmail.com
Wed Nov 23 12:49:01 CET 2011


On Wed, Nov 23, 2011 at 9:32 AM, Jaap van Arragon
<j.vanarragon at lukkien.com> wrote:
> Hello,
>
> Hopefully a short question:
>
> We have the following code in our VCL file:
>
> sub vcl_recv {
>
>     # Purge through http
>     if (req.request == "PURGE") {
>         if (!client.ip ~ purge) {
>             error 405 "Not allowed.";
>         }
>         ban("req.url =" + req.url + "&& req.http.host =" + req.http.host);
>         error 200 "Purged.";
>     }
>
>     if (req.http.cookie) {
>         unset req.http.cookie;
>         return (lookup);
>     }
>
>     if (req.http.host ~ "example.url.com") {
>         set req.backend = live;
>     }
>     else {
>         error 404 "Unkown Virtual host";
>     }
>
> When our request ( example.url.com/asdja?adn23 ) comes in we see that the
> backend is selected which it first came across. We’ve could pinpoint it to
> the unset.req.http.cookie part. If we move the unset cookie part under the
> req.http.host ~ "example.url.com" part it all goes fine.
>
> Can it be that the return(lookup); in the unset req.http.cookie part skips
> the req.http.host part? And thus the first backend is selected?

Yes. The 'return(lookup)' after the 'unset req.http.cookie' will skip
all the rest of vcl_fetch. It will lookup in the cache and go to the
vcl_hit or vcl_pass depending if the object is found or not.

You must place return(lookup) only after all required rules are done.
For example, I think this would work:

if (req.http.cookie) {
  if (req.http.host ~ "example.url.com") {
    set req.backend = live;
  }
  else {
    error 404 "Unkown Virtual host";
  }

  unset req.http.cookie;
  return (lookup);
}

Hope it will help.

-- 
[]'s
Hugo
www.devin.com.br




More information about the varnish-misc mailing list