Skip to content

Instantly share code, notes, and snippets.

@gquintard
Created March 17, 2017 13:30
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/ee47432bb8b5c97b615d973b57b6338e to your computer and use it in GitHub Desktop.
Save gquintard/ee47432bb8b5c97b615d973b57b6338e to your computer and use it in GitHub Desktop.
Test XFF ip extraction
varnishtest "XFF test"
server s1 {} -start
varnish v1 -vcl+backend {
sub vcl_recv {
return (synth(200));
}
sub vcl_synth {
set resp.http.x-cdn = regsub(req.http.xff, "([^,]+), *([^ ,]+)[ ,]?.*", "\2");
}
} -start
client c1 {
txreq -hdr "xff: 1.1.1.1, 2.2.2.2, 3.3.3.3"
rxresp
expect resp.http.x-cdn == "2.2.2.2"
txreq -hdr "xff: 1.1.1.1,2.2.2.2 , 3.3.3.3 , 4.4.4.4"
rxresp
expect resp.http.x-cdn == "2.2.2.2"
} -run
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment