5.6902 release
[catagits/Catalyst-Runtime.git] / t / 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 => 16;
10 use Catalyst::Test 'TestApp';
11
12 use Catalyst::Request;
13 use HTTP::Headers;
14 use HTTP::Request::Common;
15 use URI;
16
17 {
18     my $creq;
19
20     my $request = GET( 'http://localhost/dump/request', 
21         'User-Agent'       => 'MyAgen/1.0',
22         'X-Whats-Cool'     => 'Catalyst',
23         'X-Forwarded-Host' => 'frontend.server.com',
24         'X-Forwarded-For'  => '192.168.1.1, 1.2.3.4',
25     );
26  
27     ok( my $response = request($request), 'Request' );
28     ok( $response->is_success, 'Response Successful 2xx' );
29     is( $response->content_type, 'text/plain', 'Response Content-Type' );
30     like( $response->content, qr/^bless\( .* 'Catalyst::Request' \)$/s, 'Content is a serialized Catalyst::Request' );
31     ok( eval '$creq = ' . $response->content, 'Unserialize Catalyst::Request' );
32     isa_ok( $creq, 'Catalyst::Request' );
33     isa_ok( $creq->headers, 'HTTP::Headers', 'Catalyst::Request->headers' );
34     is( $creq->header('X-Whats-Cool'), $request->header('X-Whats-Cool'), 'Catalyst::Request->header X-Whats-Cool' );
35     is( $creq->header('User-Agent'), $request->header('User-Agent'), 'Catalyst::Request->header User-Agent' );
36
37     my $host = sprintf( '%s:%d', $request->uri->host, $request->uri->port );
38     is( $creq->header('Host'), $host, 'Catalyst::Request->header Host' );
39
40     SKIP:
41     {
42         if ( $ENV{CATALYST_SERVER} && $ENV{CATALYST_SERVER} !~ /127.0.0.1|localhost/ ) {
43             skip "Using remote server", 2;
44         }
45     
46         is( $creq->base->host, 'frontend.server.com', 'Catalyst::Request proxied base' );
47         is( $creq->address, '1.2.3.4', 'Catalyst::Request proxied address' );
48     }
49
50     SKIP:
51     {
52         if ( $ENV{CATALYST_SERVER} ) {
53             skip "Using remote server", 4;
54         }
55         # test that we can ignore the proxy support
56         TestApp->config->{ignore_frontend_proxy} = 1;
57         ok( $response = request($request), 'Request' );
58         ok( eval '$creq = ' . $response->content, 'Unserialize Catalyst::Request' );
59         is( $creq->base, 'http://localhost/', 'Catalyst::Request non-proxied base' );
60         is( $creq->address, '127.0.0.1', 'Catalyst::Request non-proxied address' );
61     }
62 }