Skip to content

Instantly share code, notes, and snippets.

@aondio
Created March 8, 2021 11:47
Show Gist options
  • Save aondio/4c054c6d058b2e2f4dc080fb47cec0e3 to your computer and use it in GitHub Desktop.
Save aondio/4c054c6d058b2e2f4dc080fb47cec0e3 to your computer and use it in GitHub Desktop.
varnishtest "Goto and fallbacks"
server s1 {
rxreq
txresp -hdr "backend:s1"
expect req.url == "/client"
rxreq
txresp -status 404 -hdr "backend:s1"
rxreq
txresp -status 503 -hdr "backend:s1"
rxreq
txresp -hdr "backend:s1"
expect req.url == "/client"
} -start
server s2 {
rxreq
txresp -hdr "backend:s2"
expect req.url == "/fallback-404"
rxreq
txresp -hdr "backend:s2"
expect req.url == "/fallback-503"
} -start
varnish v1 -vcl {
import directors;
import goto;
backend default none;
sub vcl_init {
new s1 = goto.dns_director("${s1_addr}:${s1_port}");
new s2 = goto.dns_director("${s2_addr}:${s2_port}");
}
sub vcl_recv {
set req.backend_hint = s1.backend();
return (pass);
}
sub vcl_backend_response {
if (beresp.status == 404 || beresp.status >= 500) {
set bereq.backend = s2.backend();
return(retry);
}
}
} -start
delay 1.0
client c1 {
txreq -url "/client"
rxresp
expect resp.status == 200
expect resp.http.backend == "s1"
txreq -url "/fallback-404"
rxresp
expect resp.status == 200
expect resp.http.backend == "s2"
txreq -url "/fallback-503"
rxresp
expect resp.status == 200
expect resp.http.backend == "s2"
txreq -url "/client"
rxresp
expect resp.status == 200
expect resp.http.backend == "s1"
} -run
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment