1use strict; 2no warnings; 3use Plack::Test; 4use Plack::Builder; 5use Test::More; 6use HTTP::Request::Common; 7 8my $app = sub { return [ 200, [ 'Content-Type' => 'text/plain' ], [ 'Hello' ] ] }; 9 10$app = builder { 11 enable_if { $_[0]->{HTTP_X_FOO} =~ /Bar/i } 12 'XFramework', framework => 'Testing'; 13 enable_if { $_[0]->{HTTP_X_ALLCAPS} } 14 sub { 15 my $app = shift; 16 sub { my $res = $app->($_[0]); $res->[2] = [ map uc $_, @{$res->[2]} ]; $res }; 17 }; 18 $app; 19}; 20 21test_psgi app => $app, client => sub { 22 my $cb = shift; 23 24 my($req, $res); 25 26 $req = GET "http://localhost/"; 27 $res = $cb->($req); 28 ok !$res->header('X-Framework'); 29 30 $req = GET "http://localhost/", 'X-Foo' => 'Bar'; 31 $res = $cb->($req); 32 like $res->header('X-Framework'), qr/Testing/; 33 34 $req = GET "http://localhost/", 'X-AllCaps' => 1; 35 $res = $cb->($req); 36 is $res->content, 'HELLO'; 37}; 38 39done_testing; 40