Update HTTP::Body dep so that the uploadtmp config value will work (RT #22540)
Brian Cassidy [Mon, 23 Jun 2008 22:01:06 +0000 (22:01 +0000)]
Changes
Makefile.PL
lib/Catalyst/Engine.pm
t/live_engine_request_uploads.t

diff --git a/Changes b/Changes
index 3a512b8..5160891 100644 (file)
--- a/Changes
+++ b/Changes
@@ -1,6 +1,7 @@
 # This file documents the revision history for Perl extension Catalyst.
 
 5.7xxx  xxx
+        - Update HTTP::Body dep so that the uploadtmp config value will work (RT #22540)
         - Fix for LocalRegex when used in the Root controller
         - Get some of the optional_* tests working from dirs with spaces (RT #26455)
         - Fix Catalyst::Utils::home() when application .pm is in the current dir (RT #34437)
index b60dae3..e646ca1 100644 (file)
@@ -13,7 +13,7 @@ requires 'CGI::Simple::Cookie';
 requires 'Data::Dump';
 requires 'File::Modified';
 requires 'HTML::Entities';
-requires 'HTTP::Body'    => '0.9';
+requires 'HTTP::Body'    => '1.04'; # makes uploadtmp work
 requires 'HTTP::Headers' => '1.64';
 requires 'HTTP::Request';
 requires 'HTTP::Response';
index 6935c37..424d661 100644 (file)
@@ -314,7 +314,7 @@ sub prepare_body {
         unless ( $c->request->{_body} ) {
             my $type = $c->request->header('Content-Type');
             $c->request->{_body} = HTTP::Body->new( $type, $length );
-            $c->request->{_body}->{tmpdir} = $c->config->{uploadtmp}
+            $c->request->{_body}->tmpdir( $c->config->{uploadtmp} )
               if exists $c->config->{uploadtmp};
         }
         
index d2e95ab..3bf9fe9 100644 (file)
@@ -6,7 +6,7 @@ use warnings;
 use FindBin;
 use lib "$FindBin::Bin/lib";
 
-use Test::More tests => 75;
+use Test::More tests => 88;
 use Catalyst::Test 'TestApp';
 
 use Catalyst::Request;
@@ -242,3 +242,62 @@ use HTTP::Request::Common;
         is( $upload->filename, 'catalyst_130pix.gif' );
     }
 }
+
+# test uploadtmp config var
+
+{
+    my $creq;
+
+    my $dir = "$FindBin::Bin/";
+    local TestApp->config->{ uploadtmp } = $dir;
+
+    my $request = POST(
+        'http://localhost/dump/request/',
+        'Content-Type' => 'multipart/form-data',
+        'Content'      => [
+            'testfile' => ["$FindBin::Bin/live_engine_request_uploads.t"],
+        ]
+    );
+
+    ok( my $response = request($request), 'Request' );
+    ok( $response->is_success, 'Response Successful 2xx' );
+    is( $response->content_type, 'text/plain', 'Response Content-Type' );
+    like(
+        $response->content,
+        qr/^bless\( .* 'Catalyst::Request' \)$/s,
+        'Content is a serialized Catalyst::Request'
+    );
+
+    {
+        no strict 'refs';
+        ok(
+            eval '$creq = ' . $response->content,
+            'Unserialize Catalyst::Request'
+        );
+    }
+
+    isa_ok( $creq, 'Catalyst::Request' );
+    is( $creq->method, 'POST', 'Catalyst::Request method' );
+    is( $creq->content_type, 'multipart/form-data',
+        'Catalyst::Request Content-Type' );
+    is( $creq->content_length, $request->content_length,
+        'Catalyst::Request Content-Length' );
+
+    for my $part ( $request->parts ) {
+
+        my $disposition = $part->header('Content-Disposition');
+        my %parameters  = @{ ( split_header_words($disposition) )[0] };
+
+        next unless exists $parameters{filename};
+
+        my $upload = $creq->{uploads}->{ $parameters{name} };
+
+        isa_ok( $upload, 'Catalyst::Request::Upload' );
+
+        is( $upload->type, $part->content_type, 'Upload Content-Type' );
+        is( $upload->size, length( $part->content ), 'Upload Content-Length' );
+
+        like( $upload->tempname, qr{\Q$dir\E}, 'uploadtmp' );
+    }
+}
+