- Fixed bug where content was overridden on 500 responses.
Christian Hansen [Fri, 20 Jan 2006 17:39:56 +0000 (17:39 +0000)]
Changes
MANIFEST
lib/HTTP/Request/AsCGI.pm
t/08error.t

diff --git a/Changes b/Changes
index 7ee0f5c..c2a08d5 100644 (file)
--- a/Changes
+++ b/Changes
@@ -1,6 +1,9 @@
 This file documents the revision history for Perl extension HTTP::Request::AsCGI.
 
-0.4  2006-01-06 00:00:00 2005
+0.5  2006-01-20 00:00:00 2005
+    - Fixed bug where content was overridden on 500 responses.
+
+0.4  2006-01-19 00:00:00 2005
     - Fixed #15999 return a 500 response when message is empty, reported by Chris Dolan <cdolan@cpan.org>
     - Fixed Status header bug
     - Bumped HTTP::Response requirement to 1.53 and drop our own message parsing.
index 1550996..fb8c343 100644 (file)
--- a/MANIFEST
+++ b/MANIFEST
@@ -4,10 +4,11 @@ examples/synopsis.pl
 lib/HTTP/Request/AsCGI.pm
 Makefile.PL
 MANIFEST                       This list of files
-META.yml                       Module meta-data (added by MakeMaker)
+META.yml
 README
 t/01use.t
 t/04io.t
 t/05env.t
 t/06response.t
 t/07forking.t
+t/08error.t
index a397b12..380551f 100644 (file)
@@ -12,7 +12,7 @@ use IO::File;
 
 __PACKAGE__->mk_accessors(qw[ enviroment request stdin stdout stderr ]);
 
-our $VERSION = 0.4;
+our $VERSION = 0.5;
 
 sub new {
     my $class   = shift;
@@ -151,7 +151,7 @@ sub response {
         $headers .= $line;
         last if $headers =~ /\x0d?\x0a\x0d?\x0a$/;
     }
-
+    
     unless ( defined $headers ) {
         $headers = "HTTP/1.1 500 Internal Server Error\x0d\x0a";
     }
@@ -178,8 +178,10 @@ sub response {
         $response->code($code);
         $response->message($message);
     }
+    
+    my $length = ( stat( $self->stdout ) )[7] - tell( $self->stdout );
 
-    if ( $response->code == 500 && !$response->content ) {
+    if ( $response->code == 500 && !$length ) {
 
         $response->content( $response->error_as_HTML );
         $response->content_type('text/html');
index 18b6065..f117014 100644 (file)
@@ -1,6 +1,6 @@
 #!perl
 
-use Test::More tests => 6;
+use Test::More tests => 12;
 
 use strict;
 use warnings;
@@ -26,3 +26,24 @@ is( $response->message, 'Internal Server Error', 'Response Message' );
 is( $response->protocol, 'HTTP/1.1', 'Response Protocol' );
 is( $response->content_type, 'text/html', 'Response Content-Type' );
 ok( length($response->content) > 0, 'Response Content' );
+
+{
+    my $r = HTTP::Request->new( GET => 'http://www.host.com/' );
+    my $c = HTTP::Request::AsCGI->new($r);
+
+    $c->setup;
+    
+    print "Content-Type: text/plain\n";
+    print "Status: 500 Borked\n";
+    print "\n";
+    print "Borked!";
+
+    $response = $c->restore->response;
+}
+
+isa_ok( $response, 'HTTP::Response' );
+is( $response->code, 500, 'Response Code' );
+is( $response->message, 'Borked', 'Response Message' );
+is( $response->protocol, 'HTTP/1.1', 'Response Protocol' );
+is( $response->content_type, 'text/plain', 'Response Content-Type' );
+is( $response->content, 'Borked!', 'Response Content' );