Search code examples
varnishvarnish-vcl

Varnish vcl_backend_response detect vcl_recv return (hash)


On a multiple website set-up using varnish 5.1 on port 80, I don't want to cache all domains. That is easily done in vcl_recv.

if ( req.http.Host == "cache.this.domain.com" ) {
    return(hash);
}

return(pass);

Now in vcl_backend_response I want to do some processing for cached domains.

Of course I can do if( bereq.http.Host == "cache.this.domain.com" ), but is there a way to know if it was a return(hash) or a return(pass) call in vcl_recv from within vcl_backend_response?

I thought that this could make sense but couldn't find the information.

Thanks for your help.


Solution

  • It really makes me wonder why you need such processing in the first place.

    I don't think there's a way to tell directly how you landed into vcl_backend_response. So I suppose you can set a flag and check on that later, i.e.:

    sub vcl_recv {
        if ( req.http.Host == "cache.this.domain.com" ) {
            set req.http.return_type = "hash";
            return(hash);
        }
        set req.http.return_type = "pass";
        return(pass);
    }
    
    sub vcl_backend_response {
        if( bereq.http.return_type == "pass" ) ...
    }