5 use lib "$FindBin::Bin/../lib";
9 BEGIN { $iters = $ENV{CAT_BENCH_ITERS} || 1; }
12 use Catalyst::Test 'TestApp';
14 if ( $ENV{CAT_BENCHMARK} ) {
16 Benchmark::timethis( $iters, \&run_tests );
25 # test direct streaming
27 ok( my $response = request('http://localhost/streaming'), 'Request' );
28 ok( $response->is_success, 'Response Successful 2xx' );
29 is( $response->content_type, 'text/plain', 'Response Content-Type' );
30 is( $response->header('X-Test-Header'), 'valid', 'Headers sent properly' );
31 is( $response->header('X-Test-Header-Call-Count'), 1);
35 if ( $ENV{CATALYST_SERVER} ) {
36 skip "Using remote server", 1;
39 ok(!defined $response->content_length, 'No Content-Length for streaming responses');
40 is(length $response->content, 12, 'Response content' );
43 is( $response->content,, <<'EOF', 'Content is a stream' );
50 # test streaming by passing a handle to $c->res->body
53 if ( $ENV{CATALYST_SERVER} ) {
54 skip "Using remote server", 10;
57 my $file = "$FindBin::Bin/../lib/TestApp/Controller/Action/Streaming.pm";
58 my $fh = IO::File->new( $file, 'r' );
61 $fh->read( $buffer, 2048 );
65 ok( my $response = request('http://localhost/action/streaming/body'),
67 ok( $response->is_success, 'Response Successful 2xx' );
68 is( $response->content_type, 'text/plain', 'Response Content-Type' );
69 is( $response->content_length, -s $file, 'Response Content-Length' );
70 is( $response->header('X-Test-Header'), 'valid', 'Headers sent properly' );
71 is( $response->header('X-Test-Header-Call-Count'), 1);
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->header('X-Test-Header-Call-Count'), 1);
81 is( $response->content, $buffer, 'Content is read from filehandle' );
85 my $size = 128 * 1024; # more than one read with the default chunksize
87 ok( my $response = request('http://localhost/action/streaming/body_large'), 'Request' );
88 ok( $response->is_success, 'Response Successful 2xx' );
89 is( $response->content_type, 'text/plain', 'Response Content-Type' );
90 is( $response->header('X-Test-Header'), 'valid', 'Headers sent properly' );
91 is( $response->header('X-Test-Header-Call-Count'), 1);
92 is( $response->content_length, $size, 'Response Content-Length' );
93 is( $response->content, "\0" x $size, 'Content is read from filehandle' );