Created
September 11, 2019 18:14
-
-
Save rezan/9151c305ed7902d137cc3d1f788c6377 to your computer and use it in GitHub Desktop.
Purge multiple URLs from a request body
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
varnishtest "Multipurging" | |
server s1 { | |
} -start | |
varnish v1 -vcl+backend { | |
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); | |
} | |
} | |
} -start | |
client c1 { | |
txreq -req PURGELIST -body {/foo | |
/bar} | |
rxresp | |
expect resp.status == 200 | |
} -run |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment