r4467 - in trunk/varnish-cache/bin: varnishd varnishtest/tests

phk at projects.linpro.no phk at projects.linpro.no
Mon Jan 18 14:30:47 CET 2010


Author: phk
Date: 2010-01-18 14:30:47 +0100 (Mon, 18 Jan 2010)
New Revision: 4467

Added:
   trunk/varnish-cache/bin/varnishtest/tests/b00031.vtc
Modified:
   trunk/varnish-cache/bin/varnishd/cache_http.c
   trunk/varnish-cache/bin/varnishd/default.vcl
Log:
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



Modified: trunk/varnish-cache/bin/varnishd/cache_http.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_http.c	2010-01-15 15:11:07 UTC (rev 4466)
+++ trunk/varnish-cache/bin/varnishd/cache_http.c	2010-01-18 13:30:47 UTC (rev 4467)
@@ -734,8 +734,6 @@
 		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);
 }
 
 /*--------------------------------------------------------------------

Modified: trunk/varnish-cache/bin/varnishd/default.vcl
===================================================================
--- trunk/varnish-cache/bin/varnishd/default.vcl	2010-01-15 15:11:07 UTC (rev 4466)
+++ trunk/varnish-cache/bin/varnishd/default.vcl	2010-01-18 13:30:47 UTC (rev 4467)
@@ -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" &&

Added: trunk/varnish-cache/bin/varnishtest/tests/b00031.vtc
===================================================================
--- trunk/varnish-cache/bin/varnishtest/tests/b00031.vtc	                        (rev 0)
+++ trunk/varnish-cache/bin/varnishtest/tests/b00031.vtc	2010-01-18 13:30:47 UTC (rev 4467)
@@ -0,0 +1,22 @@
+# $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



More information about the varnish-commit mailing list