Merge branch 'master' into psgi
[catagits/Catalyst-Runtime.git] / t / lib / TestApp / Controller / Action / Streaming.pm
CommitLineData
fbcc39ad 1package TestApp::Controller::Action::Streaming;
2
3use strict;
4use base 'TestApp::Controller::Action';
5
6sub streaming : Global {
7 my ( $self, $c ) = @_;
8 for my $line ( split "\n", <<'EOF' ) {
9foo
10bar
11baz
12EOF
13 $c->res->write("$line\n");
14 }
15}
16
3dc4d7e9 17sub body : Local {
18 my ( $self, $c ) = @_;
a9b467d3 19
0e155123 20 my $file = "$FindBin::Bin/../lib/TestApp/Controller/Action/Streaming.pm";
3dc4d7e9 21 my $fh = IO::File->new( $file, 'r' );
22 if ( defined $fh ) {
23 $c->res->body( $fh );
24 }
25 else {
26 $c->res->body( "Unable to read $file" );
27 }
28}
29
9c74923d 30sub body_glob : Local {
31 my ( $self, $c ) = @_;
32
33 my $file = "$FindBin::Bin/../lib/TestApp/Controller/Action/Streaming.pm";
34 open my $fh, '<', $file;
35 if ( defined $fh ) {
36 $c->res->body( $fh );
37 }
38 else {
39 $c->res->body( "Unable to read $file" );
40 }
41}
42
a9b467d3 43sub body_large : Local {
44 my ($self, $c) = @_;
45
46 # more than one write with the default chunksize
47 my $size = 128 * 1024;
48
49 my $data = "\0" x $size;
50 open my $fh, '<', \$data;
51 $c->res->content_length($size);
52 $c->res->body($fh);
53}
54
fbcc39ad 551;