fix content-length for CGI scripts that don't print any headers
[catagits/HTTP-Request-AsCGI.git] / t / 06response.t
index f3f9891..c61034a 100644 (file)
@@ -1,6 +1,6 @@
 #!perl
 
-use Test::More tests => 9;
+use Test::More tests => 16;
 
 use strict;
 use warnings;
@@ -16,7 +16,7 @@ my $response;
     my $c = HTTP::Request::AsCGI->new($r);
 
     $c->setup;
-    
+
     print "Content-Type: text/plain\n";
     print "Status: 200 Yay\n";
     print "Date: Thu, 19 Jan 2006 14:08:18 GMT\n";
@@ -37,3 +37,24 @@ is( $response->content_length, 6, 'Response Content-Length' );
 is( $response->content_type, 'text/plain', 'Response Content-Type' );
 is( $response->header('Date'), 'Thu, 19 Jan 2006 14:08:18 GMT', 'Response Date' );
 is_deeply( [ $response->header('X-Field') ], [ 1, 2 ], 'Response Header X-Field' );
+
+
+# test with a crappy cgi that doesn't actually print any headers.  actually works
+{
+    my $r = HTTP::Request->new( GET => 'http://www.host.com/' );
+    my $c = HTTP::Request::AsCGI->new($r);
+
+    $c->setup;
+
+    print "Look at me I am crappy and don't have any headers.";
+
+    $response = $c->restore->response;
+}
+
+isa_ok( $response, 'HTTP::Response' );
+is( $response->code, 200, 'Response Code' );
+is( $response->message, 'OK', 'Response Message' );
+is( $response->protocol, 'HTTP/1.1', 'Response Protocol' );
+is( $response->content, "Look at me I am crappy and don't have any headers.", 'Response Content' );
+is( $response->content_length, 50, 'Response Content-Length is right!' );
+is( $response->content_type, '', 'Response Content-Type is blank' );