Merged 5.49_01 (r1339) from refactored branch to trunk
[catagits/Catalyst-Runtime.git] / t / live / engine / response / headers.t
1 #!perl
2
3 use strict;
4 use warnings;
5
6 use FindBin;
7 use lib "$FindBin::Bin/../../lib";
8
9 use Test::More tests => 18;
10 use Catalyst::Test 'TestApp';
11 use HTTP::Request::Common;
12
13 my $content_length;
14
15 foreach my $method qw(HEAD GET) {
16     my $expected = join( ', ', 1 .. 10 );
17
18     my $request = HTTP::Request::Common->can($method)
19         ->( 'http://localhost/engine/response/headers/one' );
20
21     ok( my $response = request($request), 'Request' );
22     ok( $response->is_success, 'Response Successful 2xx' );
23     is( $response->code, 200, 'Response Code' );
24     is( $response->header('X-Catalyst-Action'),
25         'engine/response/headers/one', 'Test Action' );
26     is( $response->header('X-Header-Catalyst'),
27         'Cool', 'Response Header X-Header-Catalyst' );
28     is( $response->header('X-Header-Cool'),
29         'Catalyst', 'Response Header X-Header-Cool' );
30     is( $response->header('X-Header-Numbers'),
31         $expected, 'Response Header X-Header-Numbers' );
32
33     use bytes;
34     if ( $method eq 'HEAD' ) {
35         $content_length = $response->header('Content-Length');
36         ok( $content_length > 0, 'Response Header Content-Length' );
37         is( length($response->content),
38             0,
39             'HEAD method content is empty' );
40     }
41     elsif ( $method eq 'GET' ) {
42         # method name is echo'd back in content-body, which
43         # accounts for difference in content length.  In normal
44         # cases the Content-Length should be the same regardless
45         # of if its a GET or HEAD request.
46         SKIP:
47         {
48             if ( $ENV{CATALYST_SERVER} ) {
49                 skip "Using remote server", 2;
50             }
51             is( $response->header('Content-Length'),
52                 $content_length - 1, 'Response Header Content-Length' );
53             is( length($response->content),
54                 $response->header('Content-Length'),
55                 'GET method content' );
56         }
57     }
58 }