Catalyst-Runtime
view release on metacpan or search on metacpan
t/body_fh.t view on Meta::CPAN
use warnings;
use strict;
use Test::More;
use HTTP::Request::Common;
use HTTP::Message::PSGI;
use Plack::Util;
# Test case to check that we now send scalar and filehandle like
# bodys directly to the PSGI engine, rather than call $writer->write
# or unroll the filehandle ourselves.
{
package MyApp::Controller::Root;
use base 'Catalyst::Controller';
sub flat_response :Local {
my $response = 'Hello flat_response';
pop->res->body($response);
}
sub memory_stream :Local {
my $response = 'Hello memory_stream';
open my $fh, '<', \$response || die "$!";
pop->res->body($fh);
}
sub manual_write_fh :Local {
my ($self, $c) = @_;
my $response = 'Hello manual_write_fh';
my $writer = $c->res->write_fh;
$writer->write($response);
$writer->close;
}
sub manual_write :Local {
my ($self, $c) = @_;
$c->res->write('Hello');
$c->res->body('manual_write');
}
$INC{'MyApp/Controller/Root.pm'} = __FILE__; # sorry...
package MyApp;
use Catalyst;
}
ok(MyApp->setup);
ok(my $psgi = MyApp->psgi_app);
{
ok(my $env = req_to_psgi(GET '/root/flat_response'));
ok(my $psgi_response = $psgi->($env));
$psgi_response->(sub {
my $response_tuple = shift;
my ($status, $headers, $body) = @$response_tuple;
ok $status;
ok $headers;
( run in 0.238 second using v1.01-cache-2.11-cpan-4505f990765 )