Create branch register_actions.
[catagits/Catalyst-Runtime.git] / t / aggregate / live_engine_request_headers.t
CommitLineData
fbcc39ad 1#!perl
2
3use strict;
4use warnings;
5
6use FindBin;
ae29b412 7use lib "$FindBin::Bin/../lib";
fbcc39ad 8
ace55b07 9use Test::More tests => 17;
fbcc39ad 10use Catalyst::Test 'TestApp';
11
12use Catalyst::Request;
13use HTTP::Headers;
14use HTTP::Request::Common;
fbcc39ad 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',
ace55b07 22 'X-Multiple' => [ 1 .. 5 ],
fbcc39ad 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' );
ace55b07 35
36 { # Test that multiple headers are joined as per RFC 2616 4.2 and RFC 3875 4.1.18
37
38 my $excpected = '1, 2, 3, 4, 5';
1e0df04f 39 my $got = $creq->header('X-Multiple'); # HTTP::Headers is context sensitive, "force" scalar context
40
41 is( $got, $excpected, 'Multiple message-headers are joined as a comma-separated list' );
ace55b07 42 }
43
fbcc39ad 44 is( $creq->header('User-Agent'), $request->header('User-Agent'), 'Catalyst::Request->header User-Agent' );
45
46 my $host = sprintf( '%s:%d', $request->uri->host, $request->uri->port );
47 is( $creq->header('Host'), $host, 'Catalyst::Request->header Host' );
48
49 SKIP:
50 {
51 if ( $ENV{CATALYST_SERVER} && $ENV{CATALYST_SERVER} !~ /127.0.0.1|localhost/ ) {
52 skip "Using remote server", 2;
53 }
54
55ddccae 55 is( $creq->base->host, 'frontend.server.com', 'Catalyst::Request proxied base' );
fbcc39ad 56 is( $creq->address, '1.2.3.4', 'Catalyst::Request proxied address' );
57 }
58
59 SKIP:
60 {
61 if ( $ENV{CATALYST_SERVER} ) {
62 skip "Using remote server", 4;
63 }
64 # test that we can ignore the proxy support
65 TestApp->config->{ignore_frontend_proxy} = 1;
66 ok( $response = request($request), 'Request' );
67 ok( eval '$creq = ' . $response->content, 'Unserialize Catalyst::Request' );
68 is( $creq->base, 'http://localhost/', 'Catalyst::Request non-proxied base' );
69 is( $creq->address, '127.0.0.1', 'Catalyst::Request non-proxied address' );
70 }
71}