=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<Catalyst::Response\write> and L<Catalyst::Response\write_fh> 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' ) {
$title = $name = "$name on Catalyst $Catalyst::VERSION";
$name = "<h1>$name</h1>";
+ # Don't show context in the dump
+ $c->res->_clear_context;
+
# Don't show body parser in the dump
$c->req->_clear_body;
sub finalize_headers {
my ($self, $ctx) = @_;
- $ctx->response->finalize_headers;
+ $ctx->finalize_headers unless $ctx->response->finalized_headers;
return;
}
=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)
sub prepare_request {
my ($self, $ctx, %args) = @_;
+ $ctx->log->psgienv($args{env}) if $ctx->log->can('psgienv');
$ctx->request->_set_env($args{env});
$self->_set_env($args{env}); # Nasty back compat!
$ctx->response->_set_response_cb($args{response_cb});
return sub {
my ($respond) = @_;
+ confess("Did not get a response callback for writer, cannot continue") unless $respond;
$app->handle_request(env => $env, response_cb => $respond);
};
};
=cut
+__PACKAGE__->meta->make_immutable;
+
1;