Cleaned HTTP::Body a bit
[catagits/HTTP-Body.git] / t / 01use.t
CommitLineData
aac7ca02 1use Test::More 'no_plan';
2
3use strict;
4use FindBin;
5use_ok 'HTTP::Body';
6use YAML 'LoadFile';
7use Path::Class;
8use Data::Dumper;
9
10for my $format (qw/multipart urlencoded/) {
11 for my $match ( glob file( $FindBin::Bin, 'data', $format, '*.dat' ) ) {
12 my $file = file($match);
13 my $name = $file->basename;
14 $name =~ /^(\d+)-.*/;
15 my $num = $1;
16 my $headers =
17 LoadFile(
18 file( $FindBin::Bin, 'data', $format, "$num-headers.yml" ) );
19 my $content = $file->open('<');
20 my $body = HTTP::Body->new( $headers->{'Content-Type'},
21 $headers->{'Content-Length'} );
22 binmode $content;
23
24 while ( $content->read( my $buffer, 1024 ) ) {
25 $body->add($buffer);
26 }
27 if ( $ENV{HTTP_Body_Debug} ) {
28 warn Dumper( $body->param );
29 warn Dumper( $body->upload );
30 warn Dumper( $body->body );
31
32 warn "state : " . $body->state;
33 warn "length : " . $body->length;
34 warn "content length : " . $body->content_length;
35 warn "body length : " . ( $body->body->stat )[7] if $body->body;
36 warn "buffer : " . $body->buffer if $body->buffer;
37 }
38 ok( $body->state eq 'done' );
39 }
40}
41
421;