[patch] include client_ip in X-Forwarded-For header

Ask Bjørn Hansen ask at develooper.com
Wed Mar 28 21:28:16 UTC 2007


Currently the X-Forwarded-For header is only reset when the upstream  
is *not* trusted.

The patch below changes it so the client ip is added to the X- 
Forwarded-For header when the upstream *is* trusted.

(I noticed this was missing when I upgraded to 1.55 from CPAN rather  
than from my working copy :-) )


    - ask


Index: lib/Perlbal/BackendHTTP.pm
===================================================================
--- lib/Perlbal/BackendHTTP.pm  (revision 643)
+++ lib/Perlbal/BackendHTTP.pm  (working copy)
@@ -215,6 +215,10 @@
          $hds->header("X-Host", undef);
          $hds->header("X-Forwarded-Host", undef);
      }
+    else {
+        my @ips = split /,\s*/, ($hds->header("X-Forwarded-For") ||  
'');
+        $hds->header("X-Forwarded-For", join ", ", @ips, $client_ip);
+    }
      $self->tcp_cork(1);
      $client->state('backend_req_sent');
Index: CHANGES
===================================================================
--- CHANGES     (revision 643)
+++ CHANGES     (working copy)
@@ -1,3 +1,7 @@
+
+    -- Add the client_ip to the X-Forwarded-For header when the
+       upstream is "trusted" (Ask Bjoern Hansen).
+
1.55: 2007-03-21
      -- add plugin that returns 304 automatically on incoming requests


-- 
http://develooper.com/ - http://askask.com/




More information about the perlbal mailing list