1use strict; 2use Test::More; 3use Test::Requires qw(IO::Handle::Util LWP::UserAgent LWP::Protocol::http10); 4use IO::Handle::Util qw(:io_from); 5use HTTP::Request::Common; 6use Plack::Test; 7use Plack::Middleware::Chunked; 8 9$Plack::Test::Impl = "Server"; 10 11local $ENV{PLACK_SERVER} = "HTTP::Server::PSGI"; 12 13my @app = ( 14 sub { [ 200, [], [ 'Hello World' ] ] }, 15 sub { [ 200, [], [ 'Hello ', 'World' ] ] }, 16 sub { [ 200, [], [ 'Hello ', '', 'World' ] ] }, 17 sub { [ 200, [], io_from_array [ 'Hello World' ] ] }, 18 sub { [ 200, [], io_from_array [ 'Hello', ' World' ] ] }, 19 sub { [ 200, [], io_from_array [ 'Hello', '', ' World' ] ] }, 20); 21 22@app = (@app, @app); # for 1.0 and 1.1 23 24my $app = sub { (shift @app)->(@_) }; 25 26test_psgi 27 ua => LWP::UserAgent->new, # force LWP 28 app => Plack::Middleware::Chunked->wrap($app), client => sub { 29 my $cb = shift; 30 31 for my $proto (qw( HTTP/1.1 HTTP/1.0 )) { 32 my $is_http_10 = $proto eq 'HTTP/1.0'; 33 if ($is_http_10) { 34 LWP::Protocol::implementor('http', 'LWP::Protocol::http10'); 35 } 36 37 for (1..@app/2) { 38 my $req = GET "http://localhost/"; 39 $req->protocol($proto); 40 my $res = $cb->($req); 41 is $res->content, 'Hello World'; 42 is $res->decoded_content, 'Hello World'; 43 if ($is_http_10) { 44 isnt $res->header('client-transfer-encoding'), 'chunked', 'Chunked shouldn\'t be used in HTTP/1.0'; 45 } else { 46 is $res->header('client-transfer-encoding'), 'chunked'; 47 } 48 } 49 } 50}; 51 52done_testing; 53