actually document the new request body_data method
[catagits/Catalyst-Runtime.git] / t / aggregate / live_engine_request_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
12 use Catalyst::Request;
13 use HTTP::Headers;
14 use HTTP::Request::Common;
15
16 {
17     my $creq;
18
19     my $request = GET( 'http://localhost/dump/request', 
20         'User-Agent'       => 'MyAgen/1.0',
21         'X-Whats-Cool'     => 'Catalyst',
22         'X-Multiple'       => [ 1 .. 5 ],
23         'X-Forwarded-Host' => 'frontend.server.com',
24         'X-Forwarded-For'  => '192.168.1.1, 1.2.3.4',
25         'X-Forwarded-Port' => 443
26     );
27  
28     ok( my $response = request($request), 'Request' );
29     ok( $response->is_success, 'Response Successful 2xx' );
30     is( $response->content_type, 'text/plain', 'Response Content-Type' );
31     like( $response->content, qr/^bless\( .* 'Catalyst::Request' \)$/s, 'Content is a serialized Catalyst::Request' );
32     ok( eval '$creq = ' . $response->content, 'Unserialize Catalyst::Request' ) or fail("Exception deseializing $@ from content " . $response->content);
33     isa_ok( $creq, 'Catalyst::Request' );
34     ok( $creq->secure, 'Forwarded port sets secure' );
35     isa_ok( $creq->headers, 'HTTP::Headers', 'Catalyst::Request->headers' );
36     is( $creq->header('X-Whats-Cool'), $request->header('X-Whats-Cool'), 'Catalyst::Request->header X-Whats-Cool' );
37     
38     { # Test that multiple headers are joined as per RFC 2616 4.2 and RFC 3875 4.1.18
39
40         my $excpected = '1, 2, 3, 4, 5';
41         my $got       = $creq->header('X-Multiple'); # HTTP::Headers is context sensitive, "force" scalar context
42
43         is( $got, $excpected, 'Multiple message-headers are joined as a comma-separated list' );
44     }
45
46     is( $creq->header('User-Agent'), $request->header('User-Agent'), 'Catalyst::Request->header User-Agent' );
47
48     my $host = sprintf( '%s:%d', $request->header('X-Forwarded-Host'), $request->header('X-Forwarded-Port') );
49     is( $creq->header('Host'), $host, 'Catalyst::Request->header Host' );
50
51     SKIP:
52     {
53         if ( $ENV{CATALYST_SERVER} && $ENV{CATALYST_SERVER} !~ /127.0.0.1|localhost/ ) {
54             skip "Using remote server", 2;
55         }
56     
57         is( $creq->base->host, 'frontend.server.com', 'Catalyst::Request proxied base' );
58         is( $creq->address, '1.2.3.4', 'Catalyst::Request proxied address' );
59     }
60
61     SKIP:
62     {
63         if ( $ENV{CATALYST_SERVER} ) {
64             skip "Using remote server", 4;
65         }
66         # test that we can ignore the proxy support
67         TestApp->config->{ignore_frontend_proxy} = 1;
68         ok( $response = request($request), 'Request' );
69         ok( eval '$creq = ' . $response->content, 'Unserialize Catalyst::Request' );
70         is( $creq->base, 'http://localhost/', 'Catalyst::Request non-proxied base' );
71         is( $creq->address, '127.0.0.1', 'Catalyst::Request non-proxied address' );
72     }
73 }