| 1 |
use strict; |
| 2 |
use warnings; |
| 3 |
use Test::More; |
| 4 |
use Plack::Test; |
| 5 |
use Plack::Builder; |
| 6 |
use HTTP::Request::Common; |
| 7 |
|
| 8 |
use Plack::Middleware::Head; |
| 9 |
use Plack::Middleware::FixMissingBodyInRedirect; |
| 10 |
|
| 11 |
# No default middleware wrappers |
| 12 |
|
| 13 |
{ |
| 14 |
package MyTestApp; |
| 15 |
use Dancer2; |
| 16 |
set no_default_middleware => 1; |
| 17 |
|
| 18 |
get '/' => sub { return 'some content' }; |
| 19 |
|
| 20 |
get '/redirect' => sub { redirect '/' }; |
| 21 |
} |
| 22 |
|
| 23 |
|
| 24 |
subtest 'Head' => sub { |
| 25 |
my $plain = Plack::Test->create( MyTestApp->to_app ); |
| 26 |
my $res = $plain->request( HEAD '/' ); |
| 27 |
ok( length( $res->content ) > 0, 'HEAD request on unwrapped app has content' ); |
| 28 |
|
| 29 |
my $test = Plack::Test->create( |
| 30 |
builder { |
| 31 |
enable 'Head'; |
| 32 |
MyTestApp->to_app; |
| 33 |
} |
| 34 |
); |
| 35 |
my $response = $test->request( HEAD '/' ); |
| 36 |
is( length( $response->content ), 0, 'HEAD request on wrapped app has no content' ); |
| 37 |
|
| 38 |
is( $res->header('Content-Length'), |
| 39 |
$response->header('Content-Length'), |
| 40 |
'HEAD requests have consistent content length header' |
| 41 |
); |
| 42 |
}; |
| 43 |
|
| 44 |
subtest 'FixMissingBodyInRedirect' => sub { |
| 45 |
my $plain = Plack::Test->create( MyTestApp->to_app ); |
| 46 |
my $res = $plain->request( GET '/redirect' ); |
| 47 |
is( length( $res->content ), 0, 'GET request that redirects on unwrapped app has no content' ); |
| 48 |
|
| 49 |
my $test = Plack::Test->create( |
| 50 |
builder { |
| 51 |
enable 'FixMissingBodyInRedirect'; |
| 52 |
MyTestApp->to_app; |
| 53 |
} |
| 54 |
); |
| 55 |
my $response = $test->request( GET '/redirect' ); |
| 56 |
ok( length( $response->content ) > 0, 'GET request that redirects on wrapped app has content' ); |
| 57 |
}; |
| 58 |
|
| 59 |
done_testing; |