make etag_esi.vtc the demo for the dynamic case based on obj.can_esi

parent 36bad311
varnishtest "demo/test vmod-etag use for ESI assembled page caching"
varnishtest "demo/test vmod-etag use for ESI assembled page caching (dynamic)"
server s1 {
rxreq
expect req.url == "/esi"
txresp -body {<html><head>head</head>
txresp -hdr {Surrogate-Control: content="ESI/1.0"} \
-body {<html><head>head</head>
<esi:include src="/body"/>
footer
</html>}
rxreq
expect req.url == "/body"
txresp -body {Body Content}
txresp -hdr {Etag: "123body"} -gzipbody {Body Content}
} -start
varnish v1 -arg "-a :0 -a self=${tmpdir}/self.sock" -vcl+backend {
import etag;
import std;
# to adjust:
# - url pattern to be handled ("^/esi")
# - beresp.ttl
# - beresp.grace - important because of do_stream
......@@ -27,15 +27,26 @@ varnish v1 -arg "-a :0 -a self=${tmpdir}/self.sock" -vcl+backend {
}
sub hash_etagesi {
if (local.socket != "self") {
if (req.restarts == 0 || local.socket == "self") {
unset req.http.etagesi;
return;
}
if (req.http.etagesi) {
hash_data("etagesi");
}
}
hash_data("self");
sub deliver_etagesi {
if (obj.can_esi && req.restarts == 0 &&
local.socket != "self") {
std.rollback(req);
set req.http.etagesi = "1";
return (restart);
}
}
sub backend_fetch_etagesi {
if (local.socket == "self" || bereq.url !~ "^/esi") {
if (! bereq.http.etagesi) {
return;
}
......@@ -44,7 +55,7 @@ varnish v1 -arg "-a :0 -a self=${tmpdir}/self.sock" -vcl+backend {
}
sub backend_response_etagesi {
if (local.socket == "self" || bereq.url !~ "^/esi") {
if (! bereq.http.etagesi) {
return;
}
......@@ -69,10 +80,12 @@ varnish v1 -arg "-a :0 -a self=${tmpdir}/self.sock" -vcl+backend {
sub vcl_backend_response {
call backend_response_etagesi;
set beresp.do_esi = true;
set beresp.do_esi = beresp.http.surrogate-control ~ "ESI/1.0";
}
sub vcl_deliver {
call deliver_etagesi;
set resp.http.hits = obj.hits;
}
} -start
......@@ -94,4 +107,10 @@ client c1 {
footer
</html>}
txreq -url "/body" -hdr "Accept-Encoding: gzip"
rxresp
expect resp.status == 200
expect resp.http.hits == 1
expect resp.http.ETag == {"123body"}
} -run
varnishtest "demo/test vmod-etag use for ESI assembled page caching"
varnishtest "demo/test vmod-etag use for ESI caching with url patterns"
server s1 {
rxreq
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment