Mojolicious
view release on metacpan - search on metacpan
view release on metacpan or search on metacpan
lib/Mojo/Server/Hypnotoad.pm view on Meta::CPAN
pid_file => '/var/run/hypnotoad.pid'
Full path to process id file, defaults to C<hypnotoad.pid> in the same directory as the application. Note that this
value can only be changed after the server has been stopped.
=head2 proxy
proxy => 1
Activate reverse proxy support, which allows for the C<X-Forwarded-For> and C<X-Forwarded-Proto> headers to be picked
up automatically, defaults to the value of L<Mojo::Server/"reverse_proxy">.
=head2 requests
requests => 50
Number of keep-alive requests per connection, defaults to the value of L<Mojo::Server::Daemon/"max_requests">.
=head2 spare
lib/Mojo/Transaction.pm view on Meta::CPAN
sub is_websocket {undef}
sub remote_address {
my $self = shift;
return $self->original_remote_address(@_) if @_;
return $self->original_remote_address unless $self->req->reverse_proxy;
# Reverse proxy
my @addrs = split /\s*,\s*/, ($self->req->headers->header('X-Forwarded-For') // '');
my $trusted = $self->req->trusted_proxies;
return @addrs ? $addrs[-1] : $self->original_remote_address unless @$trusted;
push @addrs, $self->original_remote_address;
for my $addr (reverse @addrs) {
return $addr unless any { network_contains($_, $addr) } @$trusted;
}
return $addrs[0];
}
t/mojo/request.t view on Meta::CPAN
is $req->headers->content_length, 27, 'right "Content-Length" value';
};
subtest 'Parse full HTTP 1.0 request (behind reverse proxy)' => sub {
my $req = Mojo::Message::Request->new;
$req->parse('GET /foo/bar/baz.html?fo');
$req->parse("o=13 HTTP/1.0\x0d\x0aContent");
$req->parse('-Type: text/');
$req->parse("plain\x0d\x0aContent-Length: 27\x0d\x0a");
$req->parse("Host: mojolicious.org\x0d\x0a");
$req->parse("X-Forwarded-For: 192.168.2.1, 127.0.0.1\x0d\x0a\x0d\x0a");
$req->parse("Hello World!\n1234\nlalalala\n");
ok $req->is_finished, 'request is finished';
is $req->method, 'GET', 'right method';
is $req->version, '1.0', 'right version';
is $req->url, '/foo/bar/baz.html?foo=13', 'right URL';
is $req->url->to_abs, 'http://mojolicious.org/foo/bar/baz.html?foo=13', 'right absolute URL';
is $req->headers->content_type, 'text/plain', 'right "Content-Type" value';
is $req->headers->content_length, 27, 'right "Content-Length" value';
};
t/mojolicious/lite_app.t view on Meta::CPAN
# Fallback route without format
$t->get_ok('/root')->status_is(200)->header_is(Server => 'Mojolicious (Perl)')->content_is('root fallback!');
$t->get_ok('/root.txt')->status_is(200)->header_is(Server => 'Mojolicious (Perl)')->content_is('root fallback!');
# Root with format
$t->get_ok('/.html')->status_is(200)->header_exists_not('Servers')
->header_exists_not('Servers', 'the header is missing')->header_exists('Server')
->header_exists('Server', 'the header exists')->header_is(Server => 'Mojolicious (Perl)')
->content_is("/root.html\n/root.html\n/root.html\n/root.html\n/root.html\n");
subtest 'Reverse proxy with "X-Forwarded-For"' => sub {
local $ENV{MOJO_REVERSE_PROXY} = 1;
my $t = Test::Mojo->new;
$t->get_ok('/0' => {'X-Forwarded-For' => '192.0.2.2, 192.0.2.1'})->status_is(200)
->header_unlike('X-Original' => qr/192\.0\.2\.1/)->content_like(qr!http://127\.0\.0\.1:\d+/0-192\.0\.2\.1-0$!);
};
subtest 'Reverse proxy with "X-Forwarded-For" and trusted proxies' => sub {
local $ENV{MOJO_TRUSTED_PROXIES} = '127.0.0.1, 192.0.2.1';
my $t = Test::Mojo->new;
$t->get_ok('/0' => {'X-Forwarded-For' => '192.0.2.2, 192.0.2.1'})->status_is(200)
->header_unlike('X-Original' => qr/192\.0\.2\.(?:2|1)/)
->content_like(qr!http://127\.0\.0\.1:\d+/0-192\.0\.2\.2-0$!);
};
subtest 'Reverse proxy with "X-Forwarded-For" and trusted proxies (untrusted original)' => sub {
local $ENV{MOJO_TRUSTED_PROXIES} = '192.0.2.1';
my $t = Test::Mojo->new;
$t->get_ok('/0' => {'X-Forwarded-For' => '192.0.2.2, 192.0.2.1'})->status_is(200)
->header_unlike('X-Original' => qr/192\.0\.2\.(?:2|1)/)
->content_like(qr!http://127\.0\.0\.1:\d+/0-127\.0\.0\.1-0$!);
};
subtest 'Reverse proxy with "X-Forwarded-For" and trusted proxy networks' => sub {
local $ENV{MOJO_TRUSTED_PROXIES} = '127.0.0.0/8, 192.0.2.1/32';
my $t = Test::Mojo->new;
$t->get_ok('/0' => {'X-Forwarded-For' => '192.0.2.2, 192.0.2.1'})->status_is(200)
->header_unlike('X-Original' => qr/192\.0\.2\.(?:2|1)/)
->content_like(qr!http://127\.0\.0\.1:\d+/0-192\.0\.2\.2-0$!);
};
subtest 'Reverse proxy with "X-Forwarded-For" and trusted proxies (all addresses trusted)' => sub {
local $ENV{MOJO_TRUSTED_PROXIES} = '0.0.0.0/0';
my $t = Test::Mojo->new;
$t->get_ok('/0' => {'X-Forwarded-For' => '192.0.2.2, 192.0.2.1'})->status_is(200)
->header_unlike('X-Original' => qr/192\.0\.2\.(?:2|1)/)
->content_like(qr!http://127\.0\.0\.1:\d+/0-192\.0\.2\.2-0$!);
};
subtest 'Reverse proxy with "X-Forwarded-For" and trusted proxies (unexpected leading address)' => sub {
local $ENV{MOJO_TRUSTED_PROXIES} = '127.0.0.0/8, 192.0.2.1';
my $t = Test::Mojo->new;
$t->get_ok('/0' => {'X-Forwarded-For' => '7.7.7.7, 192.0.2.2, 192.0.2.1'})->status_is(200)
->header_unlike('X-Original' => qr/192\.0\.2\.(?:2|1)/)
->content_like(qr!http://127\.0\.0\.1:\d+/0-192\.0\.2\.2-0$!);
};
subtest 'Reverse proxy with "X-Forwarded-Proto"' => sub {
local $ENV{MOJO_REVERSE_PROXY} = 1;
my $t = Test::Mojo->new;
$t->get_ok('/0' => {'X-Forwarded-Proto' => 'https'})->status_is(200)->content_like(qr!^https://127\.0\.0\.1:\d+/0-!)
->content_like(qr/-0$/)->content_unlike(qr!-192\.0\.2\.1-0$!);
};
# "X-Forwarded-For"
$t->ua->server->restart;
$t->get_ok('/0' => {'X-Forwarded-For' => '192.0.2.2, 192.0.2.1'})->status_is(200)
->content_like(qr!^http://127\.0\.0\.1:\d+/0-!)->content_like(qr/-0$/)->content_unlike(qr!-192\.0\.2\.1-0$!);
# "X-Forwarded-Proto"
$t->get_ok('/0' => {'X-Forwarded-Proto' => 'https'})->status_is(200)->content_like(qr!^http://127\.0\.0\.1:\d+/0-!)
->content_like(qr/-0$/)->content_unlike(qr!-192\.0\.2\.1-0$!);
# "continue" keyword in template
$t->get_ok('/continue')->status_is(200)->content_like(qr/1.+2.+3/s);
# Inline "epl" template
view all matches for this distributionview release on metacpan - search on metacpan
( run in 0.571 second using v1.00-cache-2.02-grep-82fe00e-cpan-c9a218a2bbc )