How to set remote IP with Plack::Test
remorse opened this issue · 2 comments
remorse commented
Hi! I'm trying to write some tests using Plack::Test. In my application, I have a few special cases for particular IP addresses, for historical reasons. Is there a way to set the originating IP address in calls to request()
? (I'm using the MockHTTP client.)
Something like:
my $psgi = Plack::Test->create(Plack::Util::load_psgi('foo.psgi'));
my $res = $psgi->request(HTTP::Request->new('GET'=>'some/path', ??), ??);
in the places where I have the question marks?
Thanks,
Ricky
miyagawa commented
while you can't do that out of the box, you can easily munge your PSGI environment by either applying middleware or intercepting inline:
my $app = Plack::Util::load_psgi("foo.psgi");
my $test = Plack::Test->create(sub {
my $env = shift;
$env->{REMOTE_ADDR} = $env->{HTTP_REMOTE_ADDR};
return $app->($env);
});
my $req = HTTP::Request->new(GET ...);
$req->header( "Remote-Addr" => "1.2.3.4" );
...
remorse commented
Thanks!