Skip to content

Instantly share code, notes, and snippets.

@aondio
Created November 29, 2019 12:34
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 aondio/7c26c2c0f45a1bc4575af64dc29582e1 to your computer and use it in GitHub Desktop.
Save aondio/7c26c2c0f45a1bc4575af64dc29582e1 to your computer and use it in GitHub Desktop.
varnishtest ESI
server s1 {
rxreq
txresp -body {
<html>
Before include
<!--esi <esi:include src=""/> -->
After include
}
rxreq
txresp -body {
Included file
}
} -start
varnish v1 -arg "-p feature=+esi_disable_xml_check" -vcl {
# add our backend, and override the default backend in v_b_f
backend s1 { .host = "${s1_addr}"; .port = "${s1_port}"; }
// 1st step
sub vcl_recv {
unset req.http.x-jsonp-callback;
// 2nd step
if (req.url ~ "callback") {
set req.http.x-esi-origin-url = req.url;
// Replace the callback with our ESI template
set req.url = "/esi/jsonp-callback";
return(hash);
}
// 4th step
if (req.url == "/esi/jsonp-callback") {
set req.http.x-jsonp-callback = req.http.x-esi-origin-url + "test";
// 5th step
// Create the synthetic response
return(synth(900, "JSONP ESI"));
}
}
// 6th step
sub vcl_synth {
if (resp.status == 900) {
// We add an empty comment at the start in order to
// protect against content sniffing attacks.
// See https://miki.it/blog/2014/7/8/abusing-jsonp-with-rosetta-flash/
synthetic("/**/ " + req.http.x-jsonp-callback);
return (deliver);
}
}
sub vcl_backend_fetch {
set bereq.backend = s1;
}
sub vcl_backend_response {
set beresp.do_esi=true;
set beresp.ttl = 30s;
}
} -start
client c1 {
txreq -url "/callback"
rxresp
} -run
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment