Hi,
I wonder how I can make Varnish 4 purge based on a regex? I've found old
examples on how to do this in previous versions of Varnish but no example for
Varnish 4.
What I want to accomplish is basically this:
I send a PURGE request:
PURGE /api/news/ HTTP/1.1
This should then purge /api/news/ but also all url's with query parameters
(such as /api/news/?lang=en). I have tried the following without any success:
sub vcl_recv {
if (req.method == "PURGE") {
return (purge);
}
}
sub vcl_hash {
if (req.method == "PURGE") {
#Remove ? and everything after that
set req.http.purge-url = regsub(req.url,
"^([/a-zA-Z0-9]*)([\?=&a-zA-Z0-9]*)", "\1" );
#Make sure the url ends with a /
if(!req.http.purge-url ~ "[.]*/$"){
set req.http.purge-url = regsub(req.http.purge-url, "$", "/");
}
#Make it a regex
set req.http.purge-url = "^" + req.http.purge-url + ".*$";
hash_data(req.http.purge-url);
return (lookup);
}
}
_______________________________________________
varnish-misc mailing list
[email protected]
https://www.varnish-cache.org/lists/mailman/listinfo/varnish-misc