HTTP::Body, added support for chunked requests
[catagits/HTTP-Body.git] / t / 06octetstream.t
CommitLineData
239fb0d6 1use strict;
2use warnings;
3
0a66fd23 4use Test::More tests => 12;
239fb0d6 5
6use Cwd;
7use HTTP::Body;
8use File::Spec::Functions;
9use IO::File;
10use YAML;
11
12my $path = catdir( getcwd(), 't', 'data', 'octetstream' );
13
0a66fd23 14for ( my $i = 1 ; $i <= 3 ; $i++ ) {
239fb0d6 15
16 my $test = sprintf( "%.3d", $i );
17 my $headers = YAML::LoadFile( catfile( $path, "$test-headers.yml" ) );
18 my $results =
19 slurp_fh( IO::File->new( catfile( $path, "$test-results.dat" ) ) );
20 my $content = IO::File->new( catfile( $path, "$test-content.dat" ) );
21 my $body = HTTP::Body->new( $headers->{'Content-Type'},
22 $headers->{'Content-Length'} );
23
24 binmode $content, ':raw';
25
26 while ( $content->read( my $buffer, 1024 ) ) {
27 $body->add($buffer);
28 }
29
30 isa_ok( $body->body, 'File::Temp', "$test OctetStream body isa" );
31 my $data = slurp_fh( $body->body );
32 is_deeply( $data, $results, "$test UrlEncoded body" );
33 cmp_ok( $body->state, 'eq', 'done', "$test UrlEncoded state" );
34 cmp_ok(
35 $body->length, '==',
0a66fd23 36 $body->content_length,
239fb0d6 37 "$test UrlEncoded length"
38 );
39}
40
41sub slurp_fh {
42 my ($fh) = @_;
43 my $data = '';
44 while ( $fh->read( my $buffer, 1024 ) ) {
45 $data .= $buffer;
46 }
47 $data;
48}