How do I get the req.url in vcl_backend_response?

jnbdz picture jnbdz · Nov 28, 2014 · Viewed 9.5k times · Source

My configs are based on Varnish 3.0 and I have been updating them. But I ran into a snag.

vcl_fetch was replace to vcl_backend_response. Inside of vcl_fetch you used to be able to use req.url but not anymore inside of vcl_backend_response.

So I am left with three if statements that won't work:

sub vcl_backend_response {
     set beresp.do_esi = true;

     if (!(req.url ~ "wp-(login|admin)")) {
           unset beresp.http.set-cookie;
     }

     if ( req.http.host ~ "[0-9]\.example\.com" || req.http.host ~ "[0-9]\.example\.com") {
          set beresp.ttl = 60s;
     }

     if ( req.url ~ "\.(html|htm|css|js|txt|xml|svg)(\?[a-z0-9=]+)?$" ) {
          set beresp.do_gzip = true;
     }
}

How do I convert these configs in Varnish version 4.0?

By the way I am new to Varnish VCL.

Answer

Alex Strate picture Alex Strate · Nov 29, 2014

You have to use bereq.url now in vcl_backend_response.