|
Revision 17758, 1.2 kB
(checked in by tokuhirom, 5 years ago)
|
|
purge _build_connection
|
| Rev | Line | |
|---|
| [17384] | 1 | use Test::Base; |
|---|
| 2 | use HTTP::Engine::ResponseFinalizer; |
|---|
| 3 | use HTTP::Engine; |
|---|
| [17758] | 4 | use t::Utils; |
|---|
| [17384] | 5 | |
|---|
| [17424] | 6 | plan tests => 9+(1*blocks); |
|---|
| [17384] | 7 | |
|---|
| 8 | filters { |
|---|
| 9 | req => [qw/yaml/], |
|---|
| 10 | res => [qw/yaml/], |
|---|
| 11 | }; |
|---|
| 12 | |
|---|
| 13 | run { |
|---|
| 14 | my $block = shift; |
|---|
| [17758] | 15 | my $req = req( |
|---|
| [17384] | 16 | %{ $block->req || {} } |
|---|
| 17 | ); |
|---|
| 18 | my $res = HTTP::Engine::Response->new( |
|---|
| 19 | %{ $block->res || {} } |
|---|
| 20 | ); |
|---|
| 21 | HTTP::Engine::ResponseFinalizer->finalize( $req, $res ); |
|---|
| 22 | eval $block->test; |
|---|
| 23 | die $@ if $@; |
|---|
| [17424] | 24 | |
|---|
| 25 | do { |
|---|
| 26 | local $@; |
|---|
| 27 | eval { HTTP::Engine::ResponseFinalizer->finalize( $req ) }; |
|---|
| 28 | like $@, qr/argument missing: \$res/; |
|---|
| 29 | }; |
|---|
| [17384] | 30 | }; |
|---|
| 31 | |
|---|
| 32 | __END__ |
|---|
| 33 | |
|---|
| 34 | === default protocol |
|---|
| 35 | --- req |
|---|
| 36 | protocol: HTTP/1.0 |
|---|
| 37 | method: GET |
|---|
| 38 | --- res |
|---|
| 39 | status: 200 |
|---|
| 40 | --- test |
|---|
| 41 | is $res->protocol, 'HTTP/1.0'; |
|---|
| 42 | is $res->header('Status'), 200; |
|---|
| 43 | |
|---|
| 44 | === calcurate content_length |
|---|
| 45 | --- req |
|---|
| 46 | method: GET |
|---|
| 47 | --- res |
|---|
| 48 | body: foo |
|---|
| 49 | --- test |
|---|
| 50 | is $res->content_length, 3; |
|---|
| 51 | |
|---|
| 52 | === if error |
|---|
| 53 | --- req |
|---|
| 54 | method: GET |
|---|
| 55 | --- res |
|---|
| 56 | status: 304 |
|---|
| 57 | body: FOO |
|---|
| 58 | --- test |
|---|
| 59 | is $res->content_length, undef; |
|---|
| 60 | is $res->body, ''; |
|---|
| 61 | is $res->status, 304; |
|---|
| 62 | |
|---|
| 63 | |
|---|
| 64 | === default content type |
|---|
| 65 | --- req |
|---|
| 66 | method: GET |
|---|
| 67 | --- res |
|---|
| 68 | --- test |
|---|
| 69 | is $res->content_type, 'text/html'; |
|---|
| 70 | |
|---|
| 71 | === truncate content in HEAD request(XXX is this valid response?) |
|---|
| 72 | --- req |
|---|
| 73 | method: HEAD |
|---|
| 74 | --- res |
|---|
| 75 | body: fooo |
|---|
| 76 | --- test |
|---|
| 77 | is $res->content_length, 4; |
|---|
| 78 | is $res->body, ''; |
|---|
| 79 | |
|---|