Commit | Line | Data |
fbcc39ad |
1 | #!perl |
2 | |
3 | use strict; |
4 | use warnings; |
5 | |
6 | use FindBin; |
42da66a9 |
7 | use lib "$FindBin::Bin/../lib"; |
fbcc39ad |
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 |
43c58153 |
45 | # of whether it's a GET or HEAD request. |
fbcc39ad |
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 | } |