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