Commit | Line | Data |
a9df1200 |
1 | #!perl |
2 | |
3 | use strict; |
4 | use warnings; |
5 | |
25f2a981 |
6 | use Test::More tests => 31; |
a9df1200 |
7 | |
8 | use Cwd; |
0a66fd23 |
9 | use Digest::MD5 qw(md5_hex); |
a9df1200 |
10 | use HTTP::Body; |
11 | use File::Spec::Functions; |
12 | use IO::File; |
13 | use YAML; |
14 | |
15 | my $path = catdir( getcwd(), 't', 'data', 'urlencoded' ); |
16 | |
25f2a981 |
17 | for ( my $i = 1; $i <= 6; $i++ ) { |
a9df1200 |
18 | |
19 | my $test = sprintf( "%.3d", $i ); |
20 | my $headers = YAML::LoadFile( catfile( $path, "$test-headers.yml" ) ); |
21 | my $results = YAML::LoadFile( catfile( $path, "$test-results.yml" ) ); |
22 | my $content = IO::File->new( catfile( $path, "$test-content.dat" ) ); |
23 | my $body = HTTP::Body->new( $headers->{'Content-Type'}, $headers->{'Content-Length'} ); |
24 | |
25 | binmode $content, ':raw'; |
26 | |
27 | while ( $content->read( my $buffer, 1024 ) ) { |
28 | $body->add($buffer); |
29 | } |
30 | |
31 | is_deeply( $body->body, $results->{body}, "$test UrlEncoded body" ); |
32 | is_deeply( $body->param, $results->{param}, "$test UrlEncoded param" ); |
33 | is_deeply( $body->upload, $results->{upload}, "$test UrlEncoded upload" ); |
34 | cmp_ok( $body->state, 'eq', 'done', "$test UrlEncoded state" ); |
0a66fd23 |
35 | cmp_ok( $body->length, '==', $body->content_length, "$test UrlEncoded length" ); |
36 | |
37 | # Check trailing header on the chunked request |
38 | if ( $i == 3 ) { |
39 | my $content = IO::File->new( catfile( $path, "002-content.dat" ) ); |
40 | $content->read( my $buf, 4096 ); |
41 | is( $body->trailing_headers->header('Content-MD5'), md5_hex($buf), "$test trailing header ok" ); |
42 | } |
a9df1200 |
43 | } |