update distar url
[catagits/Catalyst-Runtime.git] / t / aggregate / live_engine_request_body_demand.t
1 use strict;
2 use warnings;
3
4 use FindBin;
5 use lib "$FindBin::Bin/../lib";
6
7 use Test::More tests => 12;
8 use Catalyst::Test 'TestAppOnDemand';
9
10 use Catalyst::Request;
11 use HTTP::Headers;
12 use HTTP::Request::Common;
13
14 # Test a simple POST request to make sure body parsing
15 # works in on-demand mode.
16 SKIP:
17 {
18     if ( $ENV{CATALYST_SERVER} ) {
19         skip "Using remote server", 12;
20     }
21
22     {
23         my $params;
24
25         my $request = POST(
26             'http://localhost/body/query_params?wibble=wobble',
27             'Content-Type' => 'application/x-www-form-urlencoded',
28             'Content'      => 'foo=bar&baz=quux'
29         );
30
31         my $expected = { wibble => 'wobble' };
32
33         ok( my $response = request($request), 'Request' );
34         ok( $response->is_success, 'Response Successful 2xx' );
35
36         {
37             no strict 'refs';
38             ok(
39                 eval '$params = ' . $response->content,
40                 'Unserialize params'
41             );
42         }
43
44         is_deeply( $params, $expected, 'Catalyst::Request query parameters' );
45     }
46
47     {
48         my $params;
49
50         my $request = POST(
51             'http://localhost/body/params?wibble=wobble',
52             'Content-Type' => 'application/x-www-form-urlencoded',
53             'Content'      => 'foo=bar&baz=quux'
54         );
55
56         my $expected = { foo => 'bar', baz => 'quux', wibble => 'wobble' };
57
58         ok( my $response = request($request), 'Request' );
59         ok( $response->is_success, 'Response Successful 2xx' );
60         {
61             no strict 'refs';
62             ok(
63                 eval '$params = ' . $response->content,
64                 'Unserialize params'
65             );
66         }
67
68         is_deeply( $params, $expected, 'Catalyst::Request body and query parameters' );
69     }
70
71     # Test reading chunks of the request body using $c->read
72     {
73         my $creq;
74
75         my $request = POST(
76             'http://localhost/body/read',
77             'Content-Type' => 'text/plain',
78             'Content'      => 'x' x 105_000
79         );
80
81         my $expected = '10000|10000|10000|10000|10000|10000|10000|10000|10000|10000|5000';
82
83         ok( my $response = request($request), 'Request' );
84         ok( $response->is_success, 'Response Successful 2xx' );
85         is( $response->content_type, 'text/plain', 'Response Content-Type' );
86         is( $response->content, $expected, 'Response Content' );
87     }
88 }