Skip to content

Instantly share code, notes, and snippets.

@rezan
Last active September 11, 2019 18:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rezan/c4a37109c878a0ce48e49c1154bc4d4d to your computer and use it in GitHub Desktop.
Save rezan/c4a37109c878a0ce48e49c1154bc4d4d to your computer and use it in GitHub Desktop.
Purge multiple urls from a request body
# Purge multiple urls from a request body
import edgestash;
import synthbackend;
import xbody;
sub vcl_recv {
unset req.http.purgelist;
if (req_top.method == "PURGELIST") {
if (req.esi_level == 0) {
set req.http.purgelist = "yes";
return(pass);
} else {
return(purge);
}
}
}
sub vcl_backend_fetch {
if (bereq.http.purgelist) {
set bereq.backend = synthbackend.mirror();
}
}
sub vcl_backend_response {
if (bereq.http.purgelist) {
xbody.regsub("(.*)\n?", "{{ > \1 }}");
edgestash.parse_response();
}
}
sub vcl_deliver {
if (req.method == "PURGELIST") {
edgestash.execute();
return (deliver);
}
if (req_top.method == "PURGELIST") {
return (synth(200));
}
}
sub vcl_synth {
if (req_top.method == "PURGELIST") {
synthetic("PURGED: " + req.url + {"
"});
return (deliver);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment