make broken-headerless-CGI content-length test a little more illustrative
[catagits/HTTP-Request-AsCGI.git] / t / 06response.t
CommitLineData
ca38286c 1#!perl
2
292e2b64 3use Test::More tests => 16;
ca38286c 4
5use strict;
6use warnings;
7
8use IO::File;
9use HTTP::Request;
10use HTTP::Request::AsCGI;
11
12my $response;
13
14{
15 my $r = HTTP::Request->new( GET => 'http://www.host.com/' );
b332ee65 16 my $c = HTTP::Request::AsCGI->new($r);
ca38286c 17
18 $c->setup;
292e2b64 19
ca38286c 20 print "Content-Type: text/plain\n";
4e0afe7d 21 print "Status: 200 Yay\n";
22 print "Date: Thu, 19 Jan 2006 14:08:18 GMT\n";
ca38286c 23 print "X-Field: 1\n";
24 print "X-Field: 2\n";
25 print "\n";
26 print "Hello!";
27
28 $response = $c->restore->response;
29}
30
31isa_ok( $response, 'HTTP::Response' );
32is( $response->code, 200, 'Response Code' );
4e0afe7d 33is( $response->message, 'Yay', 'Response Message' );
34is( $response->protocol, 'HTTP/1.1', 'Response Protocol' );
ca38286c 35is( $response->content, 'Hello!', 'Response Content' );
36is( $response->content_length, 6, 'Response Content-Length' );
37is( $response->content_type, 'text/plain', 'Response Content-Type' );
4e0afe7d 38is( $response->header('Date'), 'Thu, 19 Jan 2006 14:08:18 GMT', 'Response Date' );
ca38286c 39is_deeply( [ $response->header('X-Field') ], [ 1, 2 ], 'Response Header X-Field' );
292e2b64 40
41
42# test with a crappy cgi that doesn't actually print any headers. actually works
43{
44 my $r = HTTP::Request->new( GET => 'http://www.host.com/' );
45 my $c = HTTP::Request::AsCGI->new($r);
46
47 $c->setup;
48
f1f11f0e 49 print <<EOT;
50
51Look at me I am crappy and don't have any headers.
52
53But I have newlines and stuff. Oh yes.
54
55EOT
292e2b64 56
57 $response = $c->restore->response;
58}
59
60isa_ok( $response, 'HTTP::Response' );
61is( $response->code, 200, 'Response Code' );
62is( $response->message, 'OK', 'Response Message' );
63is( $response->protocol, 'HTTP/1.1', 'Response Protocol' );
f1f11f0e 64like( $response->content, qr/Oh yes/, 'Response Content' );
65is( $response->content_length, 93, 'Response Content-Length is right!' );
292e2b64 66is( $response->content_type, '', 'Response Content-Type is blank' );