Skip to content

Instantly share code, notes, and snippets.

@aondio
Created April 26, 2021 13:36
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/9db41d8ce86e8b927601d87f5648ebfa to your computer and use it in GitHub Desktop.
Save aondio/9db41d8ce86e8b927601d87f5648ebfa to your computer and use it in GitHub Desktop.
Override host header
varnishtest "host_header"
server s1 -repeat 2 {
rxreq
expect req.http.host == "overridden"
txresp
rxreq
expect req.http.host == "overridden"
txresp
} -start
varnish v1 -vcl {
import std;
import goto;
import directors;
backend default {
.host = "${bad_ip}";
.port = "8089";
}
sub vcl_init {
new rr = directors.fallback();
new gd1 = goto.dns_director("${s1_addr}", "${s1_port}", host_header="overridden");
rr.add_backend(gd1.backend());
if (std.healthy(gd1.backend())) { }
}
sub vcl_recv {
# unset req.http.Host;
set req.backend_hint = rr.backend();
# return (pass);
}
sub vcl_backend_fetch {
unset bereq.http.Host;
# set bereq.backend = rr.backend();
}
} -start
client c1 {
txreq -hdr "Host: foo.com"
rxresp
expect resp.status == 200
txreq -hdr "Host: bar.com"
rxresp
expect resp.status == 200
} -run
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment