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