Create branch register_actions.
[catagits/Catalyst-Runtime.git] / t / aggregate / live_engine_response_headers.t
CommitLineData
fbcc39ad 1#!perl
2
3use strict;
4use warnings;
5
6use FindBin;
ae29b412 7use lib "$FindBin::Bin/../lib";
fbcc39ad 8
9use Test::More tests => 18;
10use Catalyst::Test 'TestApp';
11use HTTP::Request::Common;
12
13my $content_length;
14
15foreach 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}