X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FCatalyst%2FEngine.pm;h=01b60c1b4722803e5dc1b5fc6bc39c350e5aeac3;hb=847e3257e923336841ed6e6769cbc12ed0409e41;hp=3a73c04fa2a7b8df2308410139be1c67ccba188f;hpb=f9b6d6122c224d2a46e1bcc4f0c98b16d0db21ce;p=catagits%2FCatalyst-Runtime.git diff --git a/lib/Catalyst/Engine.pm b/lib/Catalyst/Engine.pm index 3a73c04..01b60c1 100644 --- a/lib/Catalyst/Engine.pm +++ b/lib/Catalyst/Engine.pm @@ -312,29 +312,35 @@ sets up the L object body using L sub prepare_body { my ( $self, $c ) = @_; + + my $length = $c->request->header('Content-Length') || 0; - $self->read_length( $c->request->header('Content-Length') || 0 ); - my $type = $c->request->header('Content-Type'); + $self->read_length( $length ); - unless ( $c->request->{_body} ) { - $c->request->{_body} = HTTP::Body->new( $type, $self->read_length ); - $c->request->{_body}->{tmpdir} = $c->config->{uploadtmp} - if exists $c->config->{uploadtmp}; - } - - if ( $self->read_length > 0 ) { + if ( $length > 0 ) { + 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} + if exists $c->config->{uploadtmp}; + } + 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; + my $remaining = $length - $self->read_position; if ( $remaining > 0 ) { $self->finalize_read($c); Catalyst::Exception->throw( - "Wrong Content-Length value: " . $self->read_length ); + "Wrong Content-Length value: $length" ); } } + else { + # Defined but will cause all body code to be skipped + $c->request->{_body} = 0; + } } =head2 $self->prepare_body_chunk($c) @@ -357,6 +363,9 @@ Sets up parameters from body. sub prepare_body_parameters { my ( $self, $c ) = @_; + + return unless $c->request->{_body}; + $c->request->body_parameters( $c->request->{_body}->param ); } @@ -476,6 +485,9 @@ sub prepare_request { } sub prepare_uploads { my ( $self, $c ) = @_; + + return unless $c->request->{_body}; + my $uploads = $c->request->{_body}->upload; for my $name ( keys %$uploads ) { my $files = $uploads->{$name}; @@ -494,8 +506,20 @@ sub prepare_uploads { # support access to the filename as a normal param my @filenames = map { $_->{filename} } @uploads; - $c->request->parameters->{$name} = - @filenames > 1 ? \@filenames : $filenames[0]; + # append, if there's already params with this name + if (exists $c->request->parameters->{$name}) { + if (ref $c->request->parameters->{$name} eq 'ARRAY') { + push @{ $c->request->parameters->{$name} }, @filenames; + } + else { + $c->request->parameters->{$name} = + [ $c->request->parameters->{$name}, @filenames ]; + } + } + else { + $c->request->parameters->{$name} = + @filenames > 1 ? \@filenames : $filenames[0]; + } } }