Test uri_for with path = 0
[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         is( $response->header('Content-Length'),
41             $content_length, 'Response Header Content-Length' )
42             or diag $response->content;
43         is( length($response->content),
44             $response->header('Content-Length'),
45             'GET method content' );
46     }
47 }