Better x-forwarded-for detection

This commit is contained in:
Luc Didry
2014-02-18 02:06:11 +01:00
parent fcd1b1489b
commit 9d9e29e906
+7 -2
View File
@@ -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;
}
);