7 use lib "$FindBin::Bin/../lib";
11 BEGIN { $iters = $ENV{CAT_BENCH_ITERS} || 1; }
14 use Catalyst::Test 'TestApp';
16 if ( $ENV{CAT_BENCHMARK} ) {
18 Benchmark::timethis( $iters, \&run_tests );
27 # test direct streaming
29 ok( my $response = request('http://localhost/streaming'), 'Request' );
30 ok( $response->is_success, 'Response Successful 2xx' );
31 is( $response->content_type, 'text/plain', 'Response Content-Type' );
32 is( $response->header('X-Test-Header'), 'valid', 'Headers sent properly' );
36 if ( $ENV{CATALYST_SERVER} ) {
37 skip "Using remote server", 1;
40 ok(!defined $response->content_length, 'No Content-Length for streaming responses');
41 is(length $response->content, 12, 'Response content' );
44 is( $response->content,, <<'EOF', 'Content is a stream' );
51 # test streaming by passing a handle to $c->res->body
54 if ( $ENV{CATALYST_SERVER} ) {
55 skip "Using remote server", 10;
58 my $file = "$FindBin::Bin/../lib/TestApp/Controller/Action/Streaming.pm";
59 my $fh = IO::File->new( $file, 'r' );
62 $fh->read( $buffer, 2048 );
66 ok( my $response = request('http://localhost/action/streaming/body'),
68 ok( $response->is_success, 'Response Successful 2xx' );
69 is( $response->content_type, 'text/plain', 'Response Content-Type' );
70 is( $response->content_length, -s $file, 'Response Content-Length' );
71 is( $response->header('X-Test-Header'), 'valid', 'Headers sent properly' );
72 is( $response->content, $buffer, 'Content is read from filehandle' );
74 ok( $response = request('http://localhost/action/streaming/body_glob'),
76 ok( $response->is_success, 'Response Successful 2xx' );
77 is( $response->content_type, 'text/plain', 'Response Content-Type' );
78 is( $response->content_length, -s $file, 'Response Content-Length' );
79 is( $response->header('X-Test-Header'), 'valid', 'Headers sent properly' );
80 is( $response->content, $buffer, 'Content is read from filehandle' );
84 my $size = 128 * 1024; # more than one read with the default chunksize
86 ok( my $response = request('http://localhost/action/streaming/body_large'), 'Request' );
87 ok( $response->is_success, 'Response Successful 2xx' );
88 is( $response->content_type, 'text/plain', 'Response Content-Type' );
89 is( $response->header('X-Test-Header'), 'valid', 'Headers sent properly' );
90 is( $response->content_length, $size, 'Response Content-Length' );
91 is( $response->content, "\0" x $size, 'Content is read from filehandle' );