X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FCatalyst%2FEngine.pm;h=9f97a42859185782ddd51926d48248cc09899b9c;hb=191665f3c88f4b1f81e4198717077ac08d06bdb7;hp=2367139764d3430572bbc79c727bc2091566ba0e;hpb=0eb98ebd1624e8181a4bd88c26605f2a0f1c91d7;p=catagits%2FCatalyst-Runtime.git diff --git a/lib/Catalyst/Engine.pm b/lib/Catalyst/Engine.pm index 2367139..9f97a42 100644 --- a/lib/Catalyst/Engine.pm +++ b/lib/Catalyst/Engine.pm @@ -13,6 +13,8 @@ use URI::QueryParam; use Plack::Loader; use Catalyst::EngineLoader; use Encode (); +use Plack::Request::Upload; +use Hash::MultiValue; use utf8; use namespace::clean -except => 'meta'; @@ -54,12 +56,20 @@ See L. =head2 $self->finalize_body($c) -Finalize body. Prints the response output. +Finalize body. Prints the response output as blocking stream if it looks like +a filehandle, otherwise write it out all in one go. If there is no body in +the response, we assume you are handling it 'manually', such as for nonblocking +style or asynchronous streaming responses. You do this by calling L<\write> +several times (which sends HTTP headers if needed) or you close over C<$response->write_fh>. + +See L and L for more. =cut sub finalize_body { my ( $self, $c ) = @_; + return if $c->response->has_write_fh; + my $body = $c->response->body; no warnings 'uninitialized'; if ( blessed($body) && $body->can('read') or ref($body) eq 'GLOB' ) { @@ -561,6 +571,7 @@ sub prepare_uploads { my $uploads = $request->_body->upload; my $parameters = $request->parameters; + my @plack_uploads; foreach my $name (keys %$uploads) { my $files = $uploads->{$name}; my @uploads; @@ -575,9 +586,14 @@ sub prepare_uploads { filename => $upload->{filename}, ); push @uploads, $u; + + # Plack compatibility. + my %copy = (%$upload, headers=>$headers); + push @plack_uploads, $name, Plack::Request::Upload->new(%copy); } $request->uploads->{$name} = @uploads > 1 ? \@uploads : $uploads[0]; + # support access to the filename as a normal param my @filenames = map { $_->{filename} } @uploads; # append, if there's already params with this name @@ -593,6 +609,8 @@ sub prepare_uploads { $parameters->{$name} = @filenames > 1 ? \@filenames : $filenames[0]; } } + + $self->env->{'plack.request.upload'} ||= Hash::MultiValue->new(@plack_uploads); } =head2 $self->write($c, $buffer) @@ -685,7 +703,7 @@ sub build_psgi_app { return sub { my ($respond) = @_; - confess("Did not get a response callback for writer, cannot continiue") unless $respond; + confess("Did not get a response callback for writer, cannot continue") unless $respond; $app->handle_request(env => $env, response_cb => $respond); }; };