demo/test vmod-etag use for ESI assembled page caching

parent 61eab18d
......@@ -29,7 +29,8 @@ AM_VTC_LOG_FLAGS = \
-p vmod_path="$(abs_builddir)/.libs:$(vmoddir):$(VARNISHAPI_VMODDIR)"
TESTS = \
vtc/vmod_etag.vtc
vtc/vmod_etag.vtc \
vtc/etag_esi.vtc
# Documentation
......
varnishtest "demo/test vmod-etag use for ESI assembled page caching"
server s1 {
rxreq
expect req.url == "/esi"
txresp -body {<html><head>head</head>
<esi:include src="/body"/>
footer
</html>}
rxreq
expect req.url == "/body"
txresp -body {Body Content}
} -start
varnish v1 -arg "-a :0 -a self=${tmpdir}/self.sock" -vcl+backend {
import etag;
# to adjust:
# - url pattern to be handled ("^/esi")
# - beresp.ttl
# - beresp.grace - important because of do_stream
backend self {
.path = "${tmpdir}/self.sock";
}
sub hash_etagesi {
if (local.socket != "self") {
return;
}
hash_data("self");
}
sub backend_fetch_etagesi {
if (local.socket == "self" || bereq.url !~ "^/esi") {
return;
}
set bereq.backend = self;
return (fetch);
}
sub backend_response_etagesi {
if (local.socket == "self" || bereq.url !~ "^/esi") {
return;
}
set beresp.do_stream = false;
set beresp.do_esi = false;
set beresp.do_gunzip = true;
set beresp.ttl = 1m;
set beresp.grace = 1m;
set beresp.filters = beresp.filters + " gzip etag";
return (deliver);
}
sub vcl_hash {
call hash_etagesi;
}
sub vcl_backend_fetch {
call backend_fetch_etagesi;
}
sub vcl_backend_response {
call backend_response_etagesi;
set beresp.do_esi = true;
}
sub vcl_deliver {
set resp.http.hits = obj.hits;
}
} -start
client c1 {
txreq -url "/esi" -hdr "Accept-Encoding: gzip"
rxresp
expect resp.status == 200
expect resp.http.hits == 0
expect resp.http.ETag == {"vetag697613794b241e8317dae79d014899c6103bc6fc739192fe515b5dfa32bbdd27"}
txreq -url "/esi"
rxresp
expect resp.status == 200
expect resp.http.hits == 1
expect resp.http.ETag == {W/"vetag697613794b241e8317dae79d014899c6103bc6fc739192fe515b5dfa32bbdd27"}
expect resp.body == {<html><head>head</head>
Body Content
footer
</html>}
} -run
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