Commit | Line | Data |
1a0ea82a |
1 | use strict; |
2 | use warnings FATAL => 'all'; |
3 | |
4 | use Test::More ( |
5 | eval { require HTTP::Request::AsCGI } |
6 | ? 'no_plan' |
7 | : (skip_all => 'No HTTP::Request::AsCGI') |
8 | ); |
9 | |
10 | use HTTP::Request::Common qw(GET POST); |
11 | |
12 | my $app = StreamTest->new; |
13 | |
14 | ok run_request( $app, GET 'http://localhost/' )->is_success; |
15 | is run_request( $app, GET 'http://localhost/' )->content, "foo"; |
16 | |
1a0ea82a |
17 | sub run_request { |
18 | my ( $app, $request ) = @_; |
19 | my $c = HTTP::Request::AsCGI->new( $request )->setup; |
20 | $app->run; |
21 | $c->restore; |
22 | return $c->response; |
23 | } |
24 | |
25 | { |
26 | |
27 | package StreamTest; |
28 | use Web::Simple; |
29 | |
30 | sub dispatch_request { |
31 | |
32 | sub (GET) { |
33 | [ |
34 | sub { |
35 | my $respond = shift; |
36 | my $writer = $respond->( [ 200, [ "Content-type" => "text/plain" ] ] ); |
37 | $writer->write( 'f' ); |
38 | $writer->write( 'o' ); |
39 | $writer->write( 'o' ); |
40 | } |
41 | ]; |
42 | },; |
43 | } |
44 | } |