Plack-Middleware-RemoveRedundantBody
view release on metacpan or search on metacpan
t/response_has_redundant_body.t view on Meta::CPAN
or die "cannot open > output.txt: $!";
my $text = "<html><body>I'm file's text</body></html>";
print $fh $text;
close $fh;
open $fh, "<", "output.txt";
[100,
[ "Content-Type" => 'text/html; charset=utf-8'],
$fh];
};
mount '/code_101_body_in_file_set' => sub {
open(my $fh, ">", "output.txt")
or die "cannot open > output.txt: $!";
my $text = "<html><body>I'm file's text</body></html>";
print $fh $text;
close $fh;
open $fh, "<", "output.txt";
[101,
[ "Content-Type" => 'text/html; charset=utf-8'],
$fh];
};
mount '/code_204_body_in_file_set' => sub {
open(my $fh, ">", "output.txt")
or die "cannot open > output.txt: $!";
my $text = "<html><body>I'm file's text</body></html>";
print $fh $text;
close $fh;
open $fh, "<", "output.txt";
[204,
[ "Content-Type" => 'text/html; charset=utf-8'],
$fh];
};
mount '/code_304_body_in_file_set' => sub {
open(my $fh, ">", "output.txt")
or die "cannot open > output.txt: $!";
my $text = "<html><body>I'm file's text</body></html>";
print $fh $text;
close $fh;
open $fh, "<", "output.txt";
[304,
[ "Content-Type" => 'text/html; charset=utf-8'],
$fh];
};
# delayed response
mount '/code_200_delayed' => sub {
sub {
my $respond = shift;
$respond->( [200, [ "Content-Type" => 'text/plain' ], ['OK']] );
};
};
mount '/code_304_delayed' => sub {
sub {
my $respond = shift;
$respond->( [304, [ "Content-Type" => 'text/plain' ], ['OK']] );
};
};
# streaming response
mount '/code_200_writer' => sub {
sub {
my $respond = shift;
my $writer = $respond->( [200, [ "Content-Type" => 'text/plain' ]] );
$writer->write( ref($writer) );
$writer->close;
};
};
mount '/code_304_writer' => sub {
sub {
my $respond = shift;
my $writer = $respond->( [304, [ "Content-Type" => 'text/plain' ]] );
$writer->write( ref($writer) );
$writer->close;
};
};
},
client => sub {
my $cb = shift;
my @responses = (
[ '/code_100_no_body_set',
'',
100,
'text/html; charset=utf-8' ],
[ '/code_101_body_set',
'',
101,
'text/html; charset=utf-8' ],
[ '/code_204_body_set',
'',
204,
'text/html; charset=utf-8' ],
[ '/code_204_no_body_set',
'',
204,
'text/html; charset=utf-8' ],
[ '/code_304_body_set',
'',
304,
'text/html; charset=utf-8' ],
[ '/code_304_no_body_set',
'',
304,
'text/html; charset=utf-8' ],
[ '/code_404_body_set',
"<html><body>Body is set for 404</body></html>",
404,
'text/html; charset=utf-8' ],
[ '/code_300_body_set',
"<html><body>Body is set for 300</body></html>",
300,
'text/html; charset=utf-8' ],
[ '/code_100_no_body_in_file_set',
'',
100,
'text/html; charset=utf-8' ],
[ '/code_204_no_body_in_file_set',
'',
204,
'text/html; charset=utf-8' ],
[ '/code_304_no_body_in_file_set',
'',
304,
'text/html; charset=utf-8' ],
[ '/code_100_body_in_file_set',
'',
100,
'text/html; charset=utf-8' ],
[ '/code_101_body_in_file_set',
'',
101,
'text/html; charset=utf-8' ],
[ '/code_204_body_in_file_set',
'',
204,
'text/html; charset=utf-8' ],
[ '/code_304_body_in_file_set',
'',
304,
'text/html; charset=utf-8' ],
# delayed response
[ '/code_200_delayed',
'OK',
200,
'text/plain' ],
[ '/code_304_delayed',
'',
304,
'text/plain' ],
# streaming response
[ '/code_200_writer',
'Plack::Util::Prototype',
200,
'text/plain' ],
[ '/code_304_writer',
'Plack::Util::Prototype',
304,
'text/plain' ],
);
foreach my $response ( @responses ) {
my @response_array = @$response;
my $route = $response_array[0],
my $content = $response_array[1];
my $response_code = $response_array[2];
my $content_type = $response_array[3];
my $res = $cb->(GET $route);
is( $res->content,
$content,
"Content for $route matches $content");
is( $res->code,
$response_code,
"Response code for $route is $response_code" );
is( $res->header('Content-Type'),
$content_type,
"Content-Type for $route is $content_type");
}
};
unlink "output.txt";
done_testing;
( run in 0.581 second using v1.01-cache-2.11-cpan-5735350b133 )