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');
43 $INC{'MyApp/Controller/Root.pm'} = __FILE__; # sorry...
53 ok(my $psgi = MyApp->psgi_app);
56 ok(my $env = req_to_psgi(GET '/root/flat_response'));
57 ok(my $psgi_response = $psgi->($env));
59 $psgi_response->(sub {
60 my $response_tuple = shift;
61 my ($status, $headers, $body) = @$response_tuple;
65 is $body->[0], 'Hello flat_response';
71 ok(my $env = req_to_psgi(GET '/root/memory_stream'));
72 ok(my $psgi_response = $psgi->($env));
74 $psgi_response->(sub {
75 my $response_tuple = shift;
76 my ($status, $headers, $body) = @$response_tuple;
80 is ref($body), 'GLOB';
86 ok(my $env = req_to_psgi(GET '/root/manual_write_fh'));
87 ok(my $psgi_response = $psgi->($env));
89 $psgi_response->(sub {
90 my $response_tuple = shift;
91 my ($status, $headers, $body) = @$response_tuple;
97 return Plack::Util::inline_object(
98 write => sub { is shift, 'Hello manual_write_fh' },
99 close => sub { ok 1, 'closed' },
105 ok(my $env = req_to_psgi(GET '/root/manual_write'));
106 ok(my $psgi_response = $psgi->($env));
108 $psgi_response->(sub {
109 my $response_tuple = shift;
110 my ($status, $headers, $body) = @$response_tuple;
116 my @expected = (qw/Hello manual_write/);
117 return Plack::Util::inline_object(
118 close => sub { ok 1, 'closed'; is scalar(@expected), 0; },
119 write => sub { is shift, shift(@expected) },
124 ## We need to specify the number of expected tests because tests that live
125 ## in the callbacks might never get run (thus all ran tests pass but not all
126 ## required tests run).