Skip to content

Instantly share code, notes, and snippets.

@aondio
Created March 24, 2021 08:27
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/7aec733e1aafe97953c3487be6d2ce19 to your computer and use it in GitHub Desktop.
Save aondio/7aec733e1aafe97953c3487be6d2ce19 to your computer and use it in GitHub Desktop.
Edgestash and conditional reqs
varnishtest "Conditional Edgestash test"
server s1 {
rxreq
txresp -hdr "Etag: \"100\"" -hdr "bstatus: 200" -hdr "Content-Type: json" -body "Hello, {{first}} {{last}}!"
expect req.url == "/page.es"
rxreq
txresp -hdr "Etag: \"200\"" -body {
{
"last": "Foobar",
"first": "Chris"
}
}
expect req.url == "/page.json"
rxreq
txresp -status 304 -hdr "bstatus: 304"
expect req.url == "/page.es"
expect req.http.If-None-Match == "\"100\""
rxreq
txresp -status 304
expect req.url == "/page.json"
expect req.http.If-None-Match == "\"200\""
} -start
varnish v1 -vcl+backend {
import edgestash;
sub vcl_backend_response {
if (bereq.url ~ "\.es$") {
edgestash.parse_response();
} else if (bereq.url ~ "\.json$") {
edgestash.index_json();
}
set beresp.ttl = 0.1s;
set beresp.grace = 0s;
set beresp.keep = 100s;
}
sub vcl_deliver {
if (req.url ~ "\.es$") {
edgestash.add_json_url(regsub(req.url, "\.es$", ".json"));
edgestash.execute();
}
}
} -start
client c1 {
txreq -url "/page.es"
rxresp
expect resp.status == 200
expect resp.http.bstatus == "200"
expect resp.http.Content-Type == "json"
expect resp.body == "Hello, Chris Foobar!"
delay .3
txreq -url "/page.es"
rxresp
expect resp.status == 200
expect resp.http.bstatus == "304"
expect resp.http.Content-Type == "json"
expect resp.body == "Hello, Chris Foobar!"
} -run
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment