NAME => 'HTTP::Body',
VERSION_FROM => 'lib/HTTP/Body.pm',
PREREQ_PM => {
- YAML => 0,
- Data::Dumper => 0,
- IO::File => 0,
- List::Util => 0,
Carp => 0,
File::Temp => '0.14',
- Path::Class => 0
+ IO::File => 0,
+ List::Util => 0,
+ YAML => 0
}
);
if ( $index < 0 ) {
# make sure we have enough buffer to detect end delimiter
- my $length =
- length( $self->{buffer} ) - ( length( $self->delimiter_end ) + 2 );
+ my $length = length( $self->{buffer} ) - ( length( $self->delimiter_end ) + 2 );
unless ( $length > 0 ) {
return 0;
+#!perl
+
use Test::More 'no_plan';
use strict;
-use FindBin;
-use_ok 'HTTP::Body';
-use YAML 'LoadFile';
-use Path::Class;
-use Data::Dumper;
-
-for my $format (qw/multipart urlencoded/) {
-
- for my $match ( glob file( $FindBin::Bin, 'data', $format, '*.dat' ) ) {
- my $file = file($match);
- my $name = $file->basename;
- $name =~ /^(\d+)-.*/;
- my $num = $1;
- my $headers = LoadFile( file( $FindBin::Bin, 'data', $format, "$num-headers.yml" ) );
- my $results = LoadFile( file( $FindBin::Bin, 'data', $format, "$num-results.yml" ) );
- my $content = $file->open('<');
- my $body = HTTP::Body->new( $headers->{'Content-Type'}, $headers->{'Content-Length'} );
-
- binmode $content, ':raw';
-
- while ( $content->read( my $buffer, 1024 ) ) {
- $body->add($buffer);
- }
+use warnings;
- if ( $ENV{HTTP_BODY_DEBUG} ) {
- warn Dumper( $body->param );
- warn Dumper( $body->upload );
- warn Dumper( $body->body );
-
- warn "state : " . $body->state;
- warn "length : " . $body->length;
- warn "content length : " . $body->content_length;
- warn "body length : " . ( $body->body->stat )[7] if $body->body;
- warn "buffer : " . $body->buffer if $body->buffer;
- }
-
- for my $field ( keys %{ $body->upload } ) {
-
- my $value = $body->upload->{$field};
-
- for ( ( ref($value) eq 'ARRAY' ) ? @{$value} : $value ) {
- delete $_->{tempname};
- }
- }
-
- is_deeply( $body->body, $results->{body}, "$num-$format body" );
- is_deeply( $body->param, $results->{param}, "$num-$format param" );
- is_deeply( $body->upload, $results->{upload}, "$num-$format upload" );
- cmp_ok( $body->state, 'eq', 'done', "$num-$format state" );
- cmp_ok( $body->length, '==', $headers->{'Content-Length'}, "$num-$format length" );
- }
-}
+use_ok 'HTTP::Body';
-1;
--- /dev/null
+#!perl
+
+use strict;
+use warnings;
+
+use Test::More tests => 55;
+
+use Cwd;
+use HTTP::Body;
+use File::Spec::Functions;
+use IO::File;
+use YAML;
+
+my $path = catdir( getcwd(), 't', 'data', 'multipart' );
+
+for ( my $i = 1; $i <= 11; $i++ ) {
+
+ my $test = sprintf( "%.3d", $i );
+ my $headers = YAML::LoadFile( catfile( $path, "$test-headers.yml" ) );
+ my $results = YAML::LoadFile( catfile( $path, "$test-results.yml" ) );
+ my $content = IO::File->new( catfile( $path, "$test-content.dat" ) );
+ my $body = HTTP::Body->new( $headers->{'Content-Type'}, $headers->{'Content-Length'} );
+
+ binmode $content, ':raw';
+
+ while ( $content->read( my $buffer, 1024 ) ) {
+ $body->add($buffer);
+ }
+
+ for my $field ( keys %{ $body->upload } ) {
+
+ my $value = $body->upload->{$field};
+
+ for ( ( ref($value) eq 'ARRAY' ) ? @{$value} : $value ) {
+ delete $_->{tempname};
+ }
+ }
+
+ is_deeply( $body->body, $results->{body}, "$test MultiPart body" );
+ is_deeply( $body->param, $results->{param}, "$test MultiPart param" );
+ is_deeply( $body->upload, $results->{upload}, "$test MultiPart upload" );
+ cmp_ok( $body->state, 'eq', 'done', "$test MultiPart state" );
+ cmp_ok( $body->length, '==', $headers->{'Content-Length'}, "$test MultiPart length" );
+}
--- /dev/null
+#!perl
+
+use strict;
+use warnings;
+
+use Test::More tests => 5;
+
+use Cwd;
+use HTTP::Body;
+use File::Spec::Functions;
+use IO::File;
+use YAML;
+
+my $path = catdir( getcwd(), 't', 'data', 'urlencoded' );
+
+for ( my $i = 1; $i <= 1; $i++ ) {
+
+ my $test = sprintf( "%.3d", $i );
+ my $headers = YAML::LoadFile( catfile( $path, "$test-headers.yml" ) );
+ my $results = YAML::LoadFile( catfile( $path, "$test-results.yml" ) );
+ my $content = IO::File->new( catfile( $path, "$test-content.dat" ) );
+ my $body = HTTP::Body->new( $headers->{'Content-Type'}, $headers->{'Content-Length'} );
+
+ binmode $content, ':raw';
+
+ while ( $content->read( my $buffer, 1024 ) ) {
+ $body->add($buffer);
+ }
+
+ is_deeply( $body->body, $results->{body}, "$test UrlEncoded body" );
+ is_deeply( $body->param, $results->{param}, "$test UrlEncoded param" );
+ is_deeply( $body->upload, $results->{upload}, "$test UrlEncoded upload" );
+ cmp_ok( $body->state, 'eq', 'done', "$test UrlEncoded state" );
+ cmp_ok( $body->length, '==', $headers->{'Content-Length'}, "$test UrlEncoded length" );
+}
- A
- B
text1: Ratione accusamus aspernatur aliquam
- textarea: |-
- Voluptatem cumque voluptate sit recusandae at. Et quas facere rerum unde esse. Sit est et voluptatem. Vel temporibus velit neque odio non.
-
- Molestias rerum ut sapiente facere repellendus illo. Eum nulla quis aut. Quidem voluptas vitae ipsam officia voluptatibus eveniet. Aspernatur cupiditate ratione aliquam quidem corrupti. Eos sunt rerum non optio culpa.
+ textarea: "Voluptatem cumque voluptate sit recusandae at. Et quas facere rerum unde esse. Sit est et voluptatem. Vel temporibus velit neque odio non.\n\nMolestias rerum ut sapiente facere repellendus illo. Eum nulla quis aut. Quidem voluptas vitae ipsam officia voluptatibus eveniet. Aspernatur cupiditate ratione aliquam quidem corrupti. Eos sunt rerum non optio culpa."
upload:
upload:
- filename: hello.pl