Mojolicious的作者在IRC上指出,要查看Mojo dist中的单元测试
X-Forwarded-For
标头实现,
so I did
.
我们需要设置
$ENV{MOJO_REVERSE_PROXY}
并重新启动服务器,然后发送一个
X-Forwarded-For
头和新的IP地址和事情将只是工作。
use strict;
use warnings;
use Test::More;
use Test::Mojo;
use Mojolicious::Lite;
get '/foo' => sub { my $c = shift; $c->render( text => $c->tx->remote_address ) };
my $t = Test::Mojo->new;
$t->get_ok('/foo')->content_like(qr/\Q127.0.0.1/);
{
local $ENV{MOJO_REVERSE_PROXY} = 1;
$t->ua->server->restart;
$t->get_ok( '/foo' => { 'X-Forwarded-For' => '10.1.1.1' } )->content_like(qr/\Q10.1.1.1/);
}
done_testing;
测试现在通过了。
ok 1 - GET /foo
ok 2 - content is similar
ok 3 - GET /foo
ok 4 - content is similar
1..4