1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125
|
use strict;
use warnings;
use Test::More tests => 5;
use Plack::Test;
use Plack::Request;
use Plack::Builder;
use HTTP::Request::Common;
{
package App;
use Dancer2;
get '/' => sub {
my $dancer_req = request;
my $env = $dancer_req->env;
my $plack_req = Plack::Request->new($env);
::like(
$env->{'PATH_INFO'},
qr{^/?$},
'PATH_INFO empty or /',
);
::is(
$dancer_req->path_info,
$env->{'PATH_INFO'},
'D2 path_info matches $env',
);
::is(
$dancer_req->path_info,
$plack_req->path_info,
'D2 path_info matches Plack path_info',
);
::is( $dancer_req->path, '/', 'D2 path is /' );
::is( $plack_req->path, '/', 'Plack path is /' );
return $dancer_req->script_name;
};
get '/endpoint' => sub {
my $dancer_req = request;
my $env = $dancer_req->env;
my $plack_req = Plack::Request->new($env);
::is(
$env->{'PATH_INFO'},
'/endpoint',
'PATH_INFO /endpoint',
);
::is(
$dancer_req->path_info,
$env->{'PATH_INFO'},
'D2 path_info matches $env',
);
::is(
$dancer_req->path_info,
$plack_req->path_info,
'D2 path_info matches Plack path_info',
);
::is( $dancer_req->path, '/endpoint', 'D2 path is /' );
::is( $plack_req->path, '/endpoint', 'Plack path is /' );
return $dancer_req->script_name;
};
}
subtest '/' => sub {
my $test = Plack::Test->create( App->to_app );
my $res = $test->request( GET '/' );
ok( $res->is_success, 'Result successful' );
is( $res->content, '', 'script_name is empty' );
};
subtest '/endpoint' => sub {
my $test = Plack::Test->create( App->to_app );
my $res = $test->request( GET '/endpoint' );
ok( $res->is_success, 'Result successful' );
is( $res->content, '', 'script_name is empty' );
};
subtest '/mounted/' => sub {
my $app = builder {
mount '/' => sub { [200,[],['OK']] };
mount '/mounted' => App->to_app;
};
my $test = Plack::Test->create($app);
my $res = $test->request( GET '/mounted/' );
ok( $res->is_success, 'Result successful' );
is( $res->content, '/mounted', 'script_name is /mounted' );
};
subtest '/mounted/endpoint' => sub {
my $app = builder {
mount '/' => sub { [200,[],['OK']] };
mount '/mounted' => App->to_app;
};
my $test = Plack::Test->create($app);
my $res = $test->request( GET '/mounted/endpoint' );
ok( $res->is_success, 'Result successful' );
is( $res->content, '/mounted', 'script_name is /mounted' );
};
# Tests behaviour when SCRIPT_NAME is also the beginning of PATH_INFO
# See the discussion in #1288.
subtest '/endpoint/endpoint' => sub {
my $app = builder {
mount '/' => sub { [200,[],['OK']] };
mount '/endpoint' => App->to_app;
};
my $test = Plack::Test->create($app);
my $res = $test->request( GET '/endpoint/endpoint' );
ok( $res->is_success, 'Result successful' );
is( $res->content, '/endpoint', 'script_name is /endpoint' );
};
|