X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Runtime.git;a=blobdiff_plain;f=lib%2FCatalyst%2FEngine.pm;h=65ef3fe82039088acea1e31f9eeb8eae8d88f68e;hp=ce4074025586f4239fdb464e4bf7310098782fc2;hb=11e7af55dda3f3acd9ab3b484b54180f76b253df;hpb=ddcd2fc4728111853841078cc5d9a117b993ea96 diff --git a/lib/Catalyst/Engine.pm b/lib/Catalyst/Engine.pm index ce40740..65ef3fe 100644 --- a/lib/Catalyst/Engine.pm +++ b/lib/Catalyst/Engine.pm @@ -181,7 +181,6 @@ sub finalize_error { $name = "

$name

"; # Don't show context in the dump - $c->req->_clear_context; $c->res->_clear_context; # Don't show body parser in the dump @@ -325,29 +324,14 @@ sub finalize_error { =head2 $self->finalize_headers($c) -Abstract method, allows engines to write headers to response +Allows engines to write headers to response =cut sub finalize_headers { my ($self, $ctx) = @_; - # This is a less-than-pretty hack to avoid breaking the old - # Catalyst::Engine::PSGI. 5.9 Catalyst::Engine sets a response_cb and - # expects us to pass headers to it here, whereas Catalyst::Enngine::PSGI - # just pulls the headers out of $ctx->response in its run method and never - # sets response_cb. So take the lack of a response_cb as a sign that we - # don't need to set the headers. - - return unless ($ctx->response->_has_response_cb); - - my @headers; - $ctx->response->headers->scan(sub { push @headers, @_ }); - - my $writer = $ctx->response->_response_cb->([ $ctx->response->status, \@headers ]); - $ctx->response->_set_writer($writer); - $ctx->response->_clear_response_cb; - + $ctx->finalize_headers unless $ctx->response->finalized_headers; return; } @@ -410,14 +394,17 @@ sub prepare_body_parameters { =head2 $self->prepare_parameters($c) -sets up parameters from query and post parameters. +Sets up parameters from query and post parameters. +If parameters have already been set up will clear +existing parameters and set up again. =cut sub prepare_parameters { my ( $self, $c ) = @_; - $c->request->parameters; + $c->request->_clear_parameters; + return $c->request->parameters; } =head2 $self->prepare_path($c) @@ -537,7 +524,7 @@ sub prepare_query_parameters { =head2 $self->prepare_read($c) -prepare to read from the engine. +Prepare to read by initializing the Content-Length from headers. =cut @@ -607,6 +594,18 @@ sub prepare_uploads { } } +=head2 $self->write($c, $buffer) + +Writes the buffer to the client. + +=cut + +sub write { + my ( $self, $c, $buffer ) = @_; + + $c->response->write($buffer); +} + =head2 $self->read($c, [$maxlength]) Reads from the input stream by calling C<< $self->read_chunk >>. @@ -634,15 +633,6 @@ sub read_chunk { return $ctx->request->read_chunk(@_); } -=head2 $self->read_length - -The length of input data to be read. This is obtained from the Content-Length -header. - -=head2 $self->read_position - -The amount of input data that has already been read. - =head2 $self->run($app, $server) Start the engine. Builds a PSGI application and calls the @@ -682,8 +672,7 @@ sub run { =head2 build_psgi_app ($app, @args) -Builds and returns a PSGI application closure, wrapping it in the reverse proxy -middleware if the using_frontend_proxy config setting is set. +Builds and returns a PSGI application closure. (Raw, not wrapped in middleware) =cut @@ -695,30 +684,12 @@ sub build_psgi_app { return sub { my ($respond) = @_; + confess("Did not get a response callback for writer, cannot continiue") unless $respond; $app->handle_request(env => $env, response_cb => $respond); }; }; } -=head2 $self->write($c, $buffer) - -Writes the buffer to the client. - -=cut - -sub write { - my ( $self, $c, $buffer ) = @_; - - my $response = $c->response; - - $buffer = q[] unless defined $buffer; - - my $len = length($buffer); - $c->res->_writer->write($buffer); - - return $len; -} - =head2 $self->unescape_uri($uri) Unescapes a given URI using the most efficient method available. Engines such