HTTP-Engine

 view release on metacpan or  search on metacpan

t/010_core/responsewriter-with_io.t  view on Meta::CPAN


$out;

--- expected eval
"HTTP/1.1 200 OK
Connection: close
Content-Length: 25000
Content-Type: text/html
Status: 200

".('dummy'x5000)

=== zero size
--- input
use t::Utils;

my $writer = DummyRW->new();

my $ftmp = File::Temp->new(UNLINK => 1);
$ftmp->write('');
$ftmp->flush();
$ftmp->seek(0, File::Temp::SEEK_SET);

open my $tmp, '<', $ftmp->filename or die $!;
tie *STDOUT, 'IO::Scalar', \my $out;

my $req = req(
    protocol => 'HTTP/1.1',
    method => 'GET',
);
my $res = HTTP::Engine::Response->new(body => $tmp, status => 200);
HTTP::Engine::ResponseFinalizer->finalize( $req, $res );
$writer->finalize($req, $res);

untie *STDOUT;

$out;

--- expected eval
"HTTP/1.1 200 OK
Connection: close
Content-Length: 0
Content-Type: text/html
Status: 200

"

=== no io
--- input
use t::Utils;

my $writer = DummyRW->new();

tie *STDOUT, 'IO::Scalar', \my $out;

my $req = req(
    protocol => 'HTTP/1.1',
    method => 'GET',
);
my $res = HTTP::Engine::Response->new(body => 'OK!', status => 200);
$res->header( Connection => 'keepalive' );
HTTP::Engine::ResponseFinalizer->finalize( $req, $res );
$writer->finalize($req, $res);

untie *STDOUT;

$out;
--- expected
HTTP/1.1 200 OK
Connection: keepalive
Content-Length: 3
Content-Type: text/html
Status: 200

OK!

=== broken writer
--- input
use t::Utils;

my $writer = DummyRW->new();

my $tmp = File::Temp->new(ULINK => 1);
$tmp->write("OK!");
$tmp->flush();
$tmp->seek(0, File::Temp::SEEK_SET);

my $req = req(
    protocol => 'HTTP/1.1',
    method => 'GET',
);
my $res = HTTP::Engine::Response->new(body => $tmp, status => 200);

HTTP::Engine::ResponseFinalizer->finalize( $req, $res );
my $write;
do {
    no warnings 'redefine';
    local *DummyRW::write = sub { $write++; undef };
    $writer->finalize( $req, $res );
};
$write ? 'OK' : 'NG';

--- expected
OK



( run in 0.902 second using v1.01-cache-2.11-cpan-71847e10f99 )