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