Skip to content

Instantly share code, notes, and snippets.

@rezan
Created June 5, 2019 00:13
Show Gist options
  • Save rezan/fc106cc4504d993f6e3f20ff5376966c to your computer and use it in GitHub Desktop.
Save rezan/fc106cc4504d993f6e3f20ff5376966c to your computer and use it in GitHub Desktop.
Transform ESI to Edgestash using XBody
varnishtest "Transform ESI to Edgestash using XBody"
server s1 {
rxreq
txresp -body {
Start <esi:remove>
...
</esi:remove>
<!--esi <esi:include src="/somewhere" /> -->
<!--esi
<esi:include src=/2 />
-->
Finish
}
rxreq
txresp -body somewhere
expect req.url == "/somewhere"
rxreq
txresp -body 2
expect req.url == "/2"
} -start
varnish v1 -vcl+backend {
import edgestash;
import xbody;
sub vcl_backend_response {
xbody.regsub("<esi:remove>[\s\S]*?<\/esi:remove>", "");
xbody.regsub("<!--esi([\s\S]*?)-->", "\1");
xbody.regsub({"<esi:include src="?([\s\S]*?)"? ?\/>"}, "{{> \1 }}");
edgestash.parse_response();
}
sub vcl_deliver {
edgestash.execute();
}
} -start
client c1 {
txreq
rxresp
expect resp.status == 200
expect resp.body ~ "Start"
expect resp.body ~ "somewhere"
expect resp.body ~ "Finish"
} -run
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment