From: Tomas Doran Date: Sat, 30 Jun 2012 15:40:57 +0000 (+0100) Subject: Fix ->finalize_headers getting called twice. RT#78090 X-Git-Tag: 5.90015~2 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Runtime.git;a=commitdiff_plain;h=89ba65d5fb85ab30fa5d8109cd0d22860608605b Fix ->finalize_headers getting called twice. RT#78090 --- diff --git a/Changes b/Changes index 68a4626..78fb387 100644 --- a/Changes +++ b/Changes @@ -1,5 +1,7 @@ # This file documents the revision history for Perl extension Catalyst. + - Fix $c->finalize_headers getting called twice. RT#78090 + 5.90014 - 2012-06-26 10:00:00 - Fix calling finalize_headers before writing body when using $c->write / diff --git a/lib/Catalyst.pm b/lib/Catalyst.pm index 77bd1c5..0e15f5b 100644 --- a/lib/Catalyst.pm +++ b/lib/Catalyst.pm @@ -1788,7 +1788,7 @@ sub finalize { $c->finalize_error; } - $c->finalize_headers; + $c->finalize_headers unless $c->response->finalized_headers; # HEAD request if ( $c->request->method eq 'HEAD' ) { @@ -1898,7 +1898,7 @@ EOF $c->finalize_cookies; - $c->engine->finalize_headers( $c, @_ ); + $c->response->finalize_headers(); # Done $response->finalized_headers(1); diff --git a/lib/Catalyst/Engine.pm b/lib/Catalyst/Engine.pm index 4781e45..c414896 100644 --- a/lib/Catalyst/Engine.pm +++ b/lib/Catalyst/Engine.pm @@ -331,7 +331,7 @@ Allows engines to write headers to response sub finalize_headers { my ($self, $ctx) = @_; - $ctx->response->finalize_headers; + $ctx->finalize_headers unless $ctx->response->finalized_headers; return; } diff --git a/lib/Catalyst/Response.pm b/lib/Catalyst/Response.pm index eebe22c..6dc661e 100644 --- a/lib/Catalyst/Response.pm +++ b/lib/Catalyst/Response.pm @@ -57,7 +57,7 @@ sub write { my ( $self, $buffer ) = @_; # Finalize headers if someone manually writes output - $self->_context->finalize_headers; + $self->_context->finalize_headers unless $self->finalized_headers; $buffer = q[] unless defined $buffer; diff --git a/t/aggregate/live_component_controller_action_streaming.t b/t/aggregate/live_component_controller_action_streaming.t index f6d93ee..ba18bd7 100644 --- a/t/aggregate/live_component_controller_action_streaming.t +++ b/t/aggregate/live_component_controller_action_streaming.t @@ -30,6 +30,7 @@ sub run_tests { ok( $response->is_success, 'Response Successful 2xx' ); is( $response->content_type, 'text/plain', 'Response Content-Type' ); is( $response->header('X-Test-Header'), 'valid', 'Headers sent properly' ); + is( $response->header('X-Test-Header-Call-Count'), 1); SKIP: { @@ -69,6 +70,7 @@ EOF is( $response->content_type, 'text/plain', 'Response Content-Type' ); is( $response->content_length, -s $file, 'Response Content-Length' ); is( $response->header('X-Test-Header'), 'valid', 'Headers sent properly' ); + is( $response->header('X-Test-Header-Call-Count'), 1); is( $response->content, $buffer, 'Content is read from filehandle' ); ok( $response = request('http://localhost/action/streaming/body_glob'), @@ -77,6 +79,7 @@ EOF is( $response->content_type, 'text/plain', 'Response Content-Type' ); is( $response->content_length, -s $file, 'Response Content-Length' ); is( $response->header('X-Test-Header'), 'valid', 'Headers sent properly' ); + is( $response->header('X-Test-Header-Call-Count'), 1); is( $response->content, $buffer, 'Content is read from filehandle' ); } @@ -87,6 +90,7 @@ EOF ok( $response->is_success, 'Response Successful 2xx' ); is( $response->content_type, 'text/plain', 'Response Content-Type' ); is( $response->header('X-Test-Header'), 'valid', 'Headers sent properly' ); + is( $response->header('X-Test-Header-Call-Count'), 1); is( $response->content_length, $size, 'Response Content-Length' ); is( $response->content, "\0" x $size, 'Content is read from filehandle' ); } diff --git a/t/lib/TestApp.pm b/t/lib/TestApp.pm index d1d8797..a99301c 100644 --- a/t/lib/TestApp.pm +++ b/t/lib/TestApp.pm @@ -131,6 +131,11 @@ sub finalize_headers { $c->res->header('X-Test-Header', 'valid'); + my $call_count = $c->stash->{finalize_headers_call_count} || 0; + $call_count++; + $c->stash(finalize_headers_call_count => $call_count); + $c->res->header('X-Test-Header-Call-Count' => $call_count); + return $c->maybe::next::method(@_); }