4 use HTTP::Request::Common;
5 use HTTP::Message::PSGI;
8 # Test case to check that we now send scalar and filehandle like
9 # bodys directly to the PSGI engine, rather than call $writer->write
10 # or unroll the filehandle ourselves.
13 package MyApp::Controller::Root;
15 use base 'Catalyst::Controller';
17 sub flat_response :Local {
18 my $response = 'Hello flat_response';
19 pop->res->body($response);
22 sub memory_stream :Local {
23 my $response = 'Hello memory_stream';
24 open my $fh, '<', \$response || die "$!";
29 sub manual_write_fh :Local {
31 my $response = 'Hello manual_write_fh';
32 my $writer = $c->res->write_fh;
33 $writer->write($response);
37 sub manual_write :Local {
39 $c->res->write('Hello');
40 $c->res->body('manual_write');
48 $INC{'MyApp/Controller/Root.pm'} = '1'; # sorry...
51 ok(my $psgi = MyApp->psgi_app);
54 ok(my $env = req_to_psgi(GET '/root/flat_response'));
55 ok(my $psgi_response = $psgi->($env));
57 $psgi_response->(sub {
58 my $response_tuple = shift;
59 my ($status, $headers, $body) = @$response_tuple;
63 is $body->[0], 'Hello flat_response';
69 ok(my $env = req_to_psgi(GET '/root/memory_stream'));
70 ok(my $psgi_response = $psgi->($env));
72 $psgi_response->(sub {
73 my $response_tuple = shift;
74 my ($status, $headers, $body) = @$response_tuple;
78 is ref($body), 'GLOB';
84 ok(my $env = req_to_psgi(GET '/root/manual_write_fh'));
85 ok(my $psgi_response = $psgi->($env));
87 $psgi_response->(sub {
88 my $response_tuple = shift;
89 my ($status, $headers, $body) = @$response_tuple;
95 return Plack::Util::inline_object(
96 write => sub { is shift, 'Hello manual_write_fh' },
97 close => sub { ok 1, 'closed' },
103 ok(my $env = req_to_psgi(GET '/root/manual_write'));
104 ok(my $psgi_response = $psgi->($env));
106 $psgi_response->(sub {
107 my $response_tuple = shift;
108 my ($status, $headers, $body) = @$response_tuple;
114 my @expected = (qw/Hello manual_write/);
115 return Plack::Util::inline_object(
116 close => sub { ok 1, 'closed'; is scalar(@expected), 0; },
117 write => sub { is shift, shift(@expected) },
122 ## We need to specify the number of expected tests because tests that live
123 ## in the callbacks might never get run (thus all ran tests pass but not all
124 ## required tests run).