1#!perl 2 3use strict; 4use warnings; 5 6use Test::More qw[no_plan]; 7use lib 't'; 8use Util qw[tmpfile rewind $CRLF $LF]; 9use HTTP::Tiny; 10 11{ 12 no warnings 'redefine'; 13 sub HTTP::Tiny::Handle::can_read { 1 }; 14 sub HTTP::Tiny::Handle::can_write { 1 }; 15} 16 17{ 18 my $chunk = join('', '0' .. '9', 'A' .. 'Z', 'a' .. 'z', '_', $LF) x 16; # 1024 19 my $fh = tmpfile(); 20 my $handle = HTTP::Tiny::Handle->new(fh => $fh); 21 my $nchunks = 128; 22 my $length = $nchunks * length $chunk; 23 24 { 25 my $request = { 26 cb => sub { $nchunks-- ? $chunk : undef }, 27 headers => { 'content-length' => $length } 28 }; 29 my $got = $handle->write_content_body($request); 30 is($got, $length, "written $length octets"); 31 } 32 33 rewind($fh); 34 35 { 36 my $got = 0; 37 $handle->read_content_body(sub { $got += length $_[0] }, {}, $length); 38 is($got, $length, "read $length octets"); 39 } 40} 41 42