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 11sub _header { 12 return [ @{$_[0]}{qw/status reason headers protocol/} ] 13} 14 15{ 16 no warnings 'redefine'; 17 sub HTTP::Tiny::Handle::can_read { 1 }; 18 sub HTTP::Tiny::Handle::can_write { 1 }; 19} 20 21{ 22 my $response = join $CRLF, 'HTTP/1.1 200 OK', 'Foo: Foo', 'Bar: Bar', '', ''; 23 my $fh = tmpfile($response); 24 my $handle = HTTP::Tiny::Handle->new(fh => $fh); 25 my $exp = [ 200, 'OK', { foo => 'Foo', bar => 'Bar' }, 'HTTP/1.1' ]; 26 is_deeply(_header($handle->read_response_header), $exp, "->read_response_header CRLF"); 27} 28 29{ 30 my $response = join $LF, 'HTTP/1.1 200 OK', 'Foo: Foo', 'Bar: Bar', '', ''; 31 my $fh = tmpfile($response); 32 my $handle = HTTP::Tiny::Handle->new(fh => $fh); 33 my $exp = [ 200, 'OK', { foo => 'Foo', bar => 'Bar' }, 'HTTP/1.1' ]; 34 is_deeply(_header($handle->read_response_header), $exp, "->read_response_header LF"); 35} 36 37