Commit e6b2be5a authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

Produce the X-Forwarded-For: header in vcl_recv, so people can tweak

as they want.

Append to already existing header if possible.

NB:   If you return early from your own vcl_recv, without pasting these
lines in top of your vcl_recv, your backend gets no X-F-F header.

Fixes	#601
Fixes	#540



git-svn-id: http://www.varnish-cache.org/svn/trunk/varnish-cache@4467 d4fa192b-c00b-0410-8231-f00ffab90ce4
parent dabbcb4f
......@@ -734,8 +734,6 @@ http_FilterHeader(const struct sess *sp, unsigned how)
http_copyh(hp, sp->http, HTTP_HDR_PROTO);
http_FilterFields(sp->wrk, sp->fd, hp, sp->http, how);
http_PrintfHeader(sp->wrk, sp->fd, hp, "X-Varnish: %u", sp->xid);
http_PrintfHeader(sp->wrk, sp->fd, hp,
"X-Forwarded-For: %s", sp->addr);
}
/*--------------------------------------------------------------------
......
......@@ -40,6 +40,12 @@
*/
sub vcl_recv {
if (req.http.x-forwarded-for) {
set req.http.X-Forwarded-For =
req.http.X-Forwarded-For ", " client.ip;
} else {
set req.http.X-Forwarded-For = client.ip;
}
if (req.request != "GET" &&
req.request != "HEAD" &&
req.request != "PUT" &&
......
# $Id$
test "Test X-Forward-For headers"
server s1 {
rxreq
expect req.http.X-Forwarded-For == "127.0.0.1"
txresp
rxreq
expect req.http.X-Forwarded-For == "1.2.3.4, 127.0.0.1"
txresp
} -start
varnish v1 -vcl+backend {
} -start
client c1 {
txreq -url /1
rxresp
txreq -url /2 -hdr "X-forwarded-for: 1.2.3.4"
rxresp
} -run
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment