Skip to content

Commit

Permalink
Merge pull request plack#276 from wreis/head_streaming
Browse files Browse the repository at this point in the history
Add support for streaming app to P::M::Head
  • Loading branch information
miyagawa committed May 17, 2012
2 parents 6a0233f + 591b12d commit abf55db
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
14 changes: 13 additions & 1 deletion lib/Plack/Middleware/Head.pm
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,19 @@ sub call {

$self->response_cb($self->app->($env), sub {
my $res = shift;
$res->[2] = [];
if ( $res->[2] ) {
$res->[2] = [];
}
else {
my $done;
return sub {
unless ($done) {
return q{};
}
$done = 1;
return defined $_[0] ? q{} : undef;
};
}
});
}

Expand Down
32 changes: 32 additions & 0 deletions t/Plack-Middleware/head_streaming.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
use strict;
use Test::More;
use Plack::Test;
use Plack::Builder;
use HTTP::Request::Common;

my $app = sub {
my $env = shift;
return sub {
my $writer = shift->( [ 200, [
'Content-Type' => 'text/plain',
] ] );
$writer->write($_) for qw{Hello World};
$writer->close;
};
};

$app = builder { enable "Head"; $app };

test_psgi $app, sub {
my $cb = shift;

my $res = $cb->(GET "/");
is $res->content, "HelloWorld";

$res = $cb->(HEAD "/");
ok !$res->content;
ok(!$res->content_length);
};

done_testing;

0 comments on commit abf55db

Please sign in to comment.