Fix the case for body '0'
Tomas Doran [Fri, 17 Dec 2010 00:44:53 +0000 (00:44 +0000)]
lib/Catalyst.pm
t/aggregate/live_engine_response_emptybody.t [new file with mode: 0644]
t/lib/TestApp/Controller/Root.pm

index 45111ac..8e0f17f 100644 (file)
@@ -1857,7 +1857,7 @@ sub finalize_headers {
     }
 
     # Content-Length
-    if ( $response->body && !$response->content_length ) {
+    if ( defined $response->body && !$response->content_length ) {
 
         # get the length from a filehandle
         if ( blessed( $response->body ) && $response->body->can('read') || ref( $response->body ) eq 'GLOB' )
diff --git a/t/aggregate/live_engine_response_emptybody.t b/t/aggregate/live_engine_response_emptybody.t
new file mode 100644 (file)
index 0000000..c4d6dec
--- /dev/null
@@ -0,0 +1,27 @@
+#!perl
+
+use strict;
+use warnings;
+
+use FindBin;
+use lib "$FindBin::Bin/../lib";
+
+use Test::More;
+use Catalyst::Test 'TestApp';
+
+# body '0'
+{
+    my $res = request('/zerobody');
+    is $res->content, '0';
+    is $res->header('Content-Length'), '1';
+}
+
+# body ''
+{
+    my $res = request('/emptybody');
+    is $res->content, '';
+    ok !$res->header('Content-Length');
+}
+
+done_testing;
+
index 18c6db8..e34eacd 100644 (file)
@@ -14,6 +14,16 @@ sub zero : Path('0') {
     $c->forward('TestApp::View::Dump::Request');
 }
 
+sub zerobody : Local {
+    my ($self, $c) = @_;
+    $c->res->body('0');
+}
+
+sub emptybody : Local {
+    my ($self, $c) = @_;
+    $c->res->body('');
+}
+
 sub localregex : LocalRegex('^localregex$') {
     my ( $self, $c ) = @_;
     $c->res->header( 'X-Test-Class' => ref($self) );