I'm trying to alter a response that send to varnish ( after the initial request ) from varnish backend .
I have the code below that should clean the url querires that sent by backend , vcl_backend_response is the place that i think the code should be placed in order to clean the url before it hits to cache .
The problem is that the beresp.url doesn't exsit and the varnish doesn't compile , can you advise how this can be done ( alter the backend response ? ) ?
vcl_backend_response{
set beresp.url = regsuball(beresp.url,"(.*?)\?(.*)","\1");
}
Thanks in advance Drad
Your question is pretty unclear to me.
The bereq.url refers to the url requested to the backend by varnish... And the backend is not answering an URL.. it's answering the related content to the URL If you need to clean up the requested URL, you should probably do it in the either in the vcl_recv (to avoid multiple cache-variants see page 216 of the Varnish 6 by Example https://info.varnish-software.com/resources/varnish-6-by-example-book)
# Strip off trailing question marks
if (req.url ~ "\?$") {
set req.url = regsub(req.url, "\?$", "");
}
or into vcl_backend_fetch, with something like
# Strip off trailing question marks
if (bereq.url ~ "\?$") {
set bereq.url = regsub(bereq.url, "\?$", "");
}
Anyhow, you might be able to alter the bereq.url in the beresp procedure (if it helps ?!)