HTTP::Body, added support for chunked requests
[catagits/HTTP-Body.git] / t / 05urlencoded.t
index b73c51a..ef92262 100644 (file)
@@ -3,9 +3,10 @@
 use strict;
 use warnings;
 
-use Test::More tests => 10;
+use Test::More tests => 16;
 
 use Cwd;
+use Digest::MD5 qw(md5_hex);
 use HTTP::Body;
 use File::Spec::Functions;
 use IO::File;
@@ -13,7 +14,7 @@ use YAML;
 
 my $path = catdir( getcwd(), 't', 'data', 'urlencoded' );
 
-for ( my $i = 1; $i <= 2; $i++ ) {
+for ( my $i = 1; $i <= 3; $i++ ) {
 
     my $test    = sprintf( "%.3d", $i );
     my $headers = YAML::LoadFile( catfile( $path, "$test-headers.yml" ) );
@@ -31,5 +32,12 @@ for ( my $i = 1; $i <= 2; $i++ ) {
     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" );
+    cmp_ok( $body->length, '==', $body->content_length, "$test UrlEncoded length" );
+    
+    # Check trailing header on the chunked request
+    if ( $i == 3 ) {
+        my $content = IO::File->new( catfile( $path, "002-content.dat" ) );
+        $content->read( my $buf, 4096 );
+        is( $body->trailing_headers->header('Content-MD5'), md5_hex($buf), "$test trailing header ok" );
+    }
 }