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