From: Matt S Trout Date: Sat, 28 Jan 2006 15:53:52 +0000 (+0000) Subject: - Updated POST upload handling patch from miyagawa X-Git-Tag: 5.7099_04~724 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Runtime.git;a=commitdiff_plain;h=fdb3773e12efa92b61ce7e128ef0444f1d1b4e67 - Updated POST upload handling patch from miyagawa --- diff --git a/lib/Catalyst/Engine.pm b/lib/Catalyst/Engine.pm index 44176bc..963ac5a 100644 --- a/lib/Catalyst/Engine.pm +++ b/lib/Catalyst/Engine.pm @@ -312,6 +312,13 @@ sub prepare_body { while ( my $buffer = $self->read($c) ) { $c->prepare_body_chunk($buffer); } + + # paranoia against wrong Content-Length header + my $remaining = $self->read_length - $self->read_position; + if ($remaining > 0) { + $self->finalize_read($c); + Catalyst::Exception->throw("Wrong Content-Length value: ". $self->read_length); + } } } diff --git a/t/live_engine_request_uploads.t b/t/live_engine_request_uploads.t index 48a215d..bc43716 100644 --- a/t/live_engine_request_uploads.t +++ b/t/live_engine_request_uploads.t @@ -6,7 +6,7 @@ use warnings; use FindBin; use lib "$FindBin::Bin/lib"; -use Test::More tests => 52; +use Test::More tests => 59; use Catalyst::Test 'TestApp'; use Catalyst::Request; @@ -146,3 +146,32 @@ use HTTP::Request::Common; is( $response->content_type, 'text/plain', 'Response Content-Type' ); is( $response->content, ( $request->parts )[0]->content, 'Content' ); } + +{ + my $request = POST( + 'http://localhost/dump/request', + 'Content-Type' => 'multipart/form-data', + 'Content' => + [ 'file' => ["$FindBin::Bin/catalyst_130pix.gif"], ] + ); + + # Sending wrong Content-Length here and see if subequent requests fail + $request->header('Content-Length' => $request->header('Content-Length') + 1); + + ok( my $response = request($request), 'Request' ); + ok( !$response->is_success, 'Response Error' ); + + $request = POST( + 'http://localhost/dump/request', + 'Content-Type' => 'multipart/form-data', + 'Content' => + [ 'file1' => ["$FindBin::Bin/catalyst_130pix.gif"], + 'file2' => ["$FindBin::Bin/catalyst_130pix.gif"], ] + ); + + ok( $response = request($request), 'Request' ); + ok( $response->is_success, 'Response Successful 2xx' ); + is( $response->content_type, 'text/plain', 'Response Content-Type' ); + like( $response->content, qr/file1 => bless/, 'Upload with name file1'); + like( $response->content, qr/file2 => bless/, 'Upload with name file2'); +}