actually document the new request body_data method
[catagits/Catalyst-Runtime.git] / t / aggregate / live_engine_request_body.t
1 #!perl
2 use strict;
3 use warnings;
4
5 use FindBin;
6 use lib "$FindBin::Bin/../lib";
7
8 use Test::More tests => 23;
9 use Catalyst::Test 'TestApp';
10
11 use Catalyst::Request;
12 use HTTP::Headers;
13 use HTTP::Request::Common;
14
15 {
16     my $creq;
17
18     my $request = POST(
19         'http://localhost/dump/request/',
20         'Content-Type' => 'text/plain',
21         'Content'      => 'Hello Catalyst'
22     );
23
24     ok( my $response = request($request), 'Request' );
25     ok( $response->is_success, 'Response Successful 2xx' );
26     is( $response->content_type, 'text/plain', 'Response Content-Type' );
27     like( $response->content, qr/'Catalyst::Request'/,
28         'Content is a serialized Catalyst::Request' );
29
30     {
31         no strict 'refs';
32         ok(
33             eval '$creq = ' . $response->content,
34             'Unserialize Catalyst::Request'
35         );
36     }
37
38     isa_ok( $creq, 'Catalyst::Request' );
39     is( $creq->method,       'POST',       'Catalyst::Request method' );
40     is( $creq->content_type, 'text/plain', 'Catalyst::Request Content-Type' );
41     is( $creq->{__body_type}, 'File::Temp' );
42     is( $creq->content_length, $request->content_length,
43         'Catalyst::Request Content-Length' );
44 }
45
46 {
47     my $creq;
48
49     my $request = POST(
50         'http://localhost/dump/request/',
51         'Content-Type' => 'text/plain',
52         'Content'      => 'x' x 100_000
53     );
54
55     ok( my $response = request($request), 'Request' );
56     ok( $response->is_success, 'Response Successful 2xx' );
57     is( $response->content_type, 'text/plain', 'Response Content-Type' );
58     like(
59         $response->content,
60         qr/^bless\( .* 'Catalyst::Request' \)$/s,
61         'Content is a serialized Catalyst::Request'
62     );
63
64     {
65         no strict 'refs';
66         ok(
67             eval '$creq = ' . $response->content,
68             'Unserialize Catalyst::Request'
69         );
70     }
71
72     isa_ok( $creq, 'Catalyst::Request' );
73     is( $creq->method,       'POST',       'Catalyst::Request method' );
74     is( $creq->content_type, 'text/plain', 'Catalyst::Request Content-Type' );
75     is( $creq->{__body_type}, 'File::Temp' );
76     is( $creq->content_length, $request->content_length,
77         'Catalyst::Request Content-Length' );
78 }
79
80 # 5.80 regression, see note in Catalyst::Plugin::Test::Plugin
81 {
82     my $request = GET(
83         'http://localhost/dump/response',
84         'Content-Type' => 'text/plain',
85         'Content'      => 'x' x 100_000
86     );
87
88     ok( my $response = request($request), 'Request' );
89     ok( $response->is_success, 'Response Successful 2xx' );
90     ok( $response->header('X-Have-Request-Body'), 'X-Have-Request-Body set' );
91 }
92