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 { server s1 {
rxreq rxreq
expect req.url == "/esi" 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"/> <esi:include src="/body"/>
footer footer
</html>} </html>}
rxreq rxreq
expect req.url == "/body" expect req.url == "/body"
txresp -body {Body Content} txresp -hdr {Etag: "123body"} -gzipbody {Body Content}
} -start } -start
varnish v1 -arg "-a :0 -a self=${tmpdir}/self.sock" -vcl+backend { varnish v1 -arg "-a :0 -a self=${tmpdir}/self.sock" -vcl+backend {
import etag; import etag;
import std;
# to adjust: # to adjust:
# - url pattern to be handled ("^/esi")
# - beresp.ttl # - beresp.ttl
# - beresp.grace - important because of do_stream # - beresp.grace - important because of do_stream
...@@ -27,15 +27,26 @@ varnish v1 -arg "-a :0 -a self=${tmpdir}/self.sock" -vcl+backend { ...@@ -27,15 +27,26 @@ varnish v1 -arg "-a :0 -a self=${tmpdir}/self.sock" -vcl+backend {
} }
sub hash_etagesi { sub hash_etagesi {
if (local.socket != "self") { if (req.restarts == 0 || local.socket == "self") {
unset req.http.etagesi;
return; 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 { sub backend_fetch_etagesi {
if (local.socket == "self" || bereq.url !~ "^/esi") { if (! bereq.http.etagesi) {
return; return;
} }
...@@ -44,7 +55,7 @@ varnish v1 -arg "-a :0 -a self=${tmpdir}/self.sock" -vcl+backend { ...@@ -44,7 +55,7 @@ varnish v1 -arg "-a :0 -a self=${tmpdir}/self.sock" -vcl+backend {
} }
sub backend_response_etagesi { sub backend_response_etagesi {
if (local.socket == "self" || bereq.url !~ "^/esi") { if (! bereq.http.etagesi) {
return; return;
} }
...@@ -69,10 +80,12 @@ varnish v1 -arg "-a :0 -a self=${tmpdir}/self.sock" -vcl+backend { ...@@ -69,10 +80,12 @@ varnish v1 -arg "-a :0 -a self=${tmpdir}/self.sock" -vcl+backend {
sub vcl_backend_response { sub vcl_backend_response {
call backend_response_etagesi; call backend_response_etagesi;
set beresp.do_esi = true; set beresp.do_esi = beresp.http.surrogate-control ~ "ESI/1.0";
} }
sub vcl_deliver { sub vcl_deliver {
call deliver_etagesi;
set resp.http.hits = obj.hits; set resp.http.hits = obj.hits;
} }
} -start } -start
...@@ -94,4 +107,10 @@ client c1 { ...@@ -94,4 +107,10 @@ client c1 {
footer footer
</html>} </html>}
txreq -url "/body" -hdr "Accept-Encoding: gzip"
rxresp
expect resp.status == 200
expect resp.http.hits == 1
expect resp.http.ETag == {"123body"}
} -run } -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 { server s1 {
rxreq 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