From 9d9e29e9067a6aaf92b6c962f80e2e2c17b25f72 Mon Sep 17 00:00:00 2001 From: Luc Didry Date: Tue, 18 Feb 2014 02:06:11 +0100 Subject: [PATCH] Better x-forwarded-for detection --- lib/Lutim.pm | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/Lutim.pm b/lib/Lutim.pm index 524ee61..1abae1a 100644 --- a/lib/Lutim.pm +++ b/lib/Lutim.pm @@ -56,8 +56,13 @@ sub startup { $self->helper( ip => sub { my $c = shift; - my @ip = ($c->tx->remote_address eq '127.0.0.1' && $c->app->mode eq 'production') ? $c->tx->req->{content}->{headers}->{headers}->{'x-forwarded-for'}->[0]->[0] : ($c->tx->remote_address); - return join(',', @ip); + + my $proxy = ''; + my @x_forward = $c->req->headers->header('X-Forwarded-For'); + for my $x (@x_forward) { + $proxy .= join(', ', @$x); + } + return ($proxy) ? $proxy : $c->tx->remote_address; } );