Skip to content

Instantly share code, notes, and snippets.

@gquintard
Created December 18, 2016 16:25
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 gquintard/f2c472090e1ec7d3a42d0b9430717ce3 to your computer and use it in GitHub Desktop.
Save gquintard/f2c472090e1ec7d3a42d0b9430717ce3 to your computer and use it in GitHub Desktop.
varnishtest "Long vcl/backend names"
server s1 {
rxreq
txresp -status 301 -hdr "Location: http://bar.example.com/bar"
expect req.http.host == "foo.example.com"
expect req.url == "/foo"
rxreq
txresp -status 301 -hdr "Location: http://baz.example.com/baz"
expect req.http.host == "bar.example.com"
expect req.url == "/bar"
rxreq
txresp -hdr "final: true"
expect req.http.host == "baz.example.com"
expect req.url == "/baz"
} -start
varnish v1 -vcl+backend {
import std;
sub vcl_backend_response {
if (beresp.status == 301 && beresp.http.location ~ "^https?://[^/]+/") {
set bereq.http.host = regsuball(beresp.http.location, "^https?://([^/]+)/.*", "\1");
set bereq.url = regsuball(beresp.http.location, "^https?://([^/]+)", "");
return (retry);
}
}
} -start
client c1 {
txreq -url "/foo" -hdr "host: foo.example.com"
rxresp
expect resp.status == 200
expect resp.http.final == "true"
} -run
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment