Skip to content
Browse files

Add support for streaming to P::M::ConditionalGET

  • Loading branch information...
1 parent b2f3ffb commit c1e56844446fff160cc257e257279415a8bcb658 Wallace Reis committed Mar 27, 2012
Showing with 15 additions and 5 deletions.
  1. +13 −2 lib/Plack/Middleware/ConditionalGET.pm
  2. +2 −3 t/Plack-Middleware/conditionalget_writer.t
View
15 lib/Plack/Middleware/ConditionalGET.pm
@@ -12,13 +12,24 @@ sub call {
$self->response_cb($res, sub {
my $res = shift;
- return unless $res->[2]; # do not support streaming interface
my $h = Plack::Util::headers($res->[1]);
if ( $self->etag_matches($h, $env) || $self->not_modified_since($h, $env) ) {
$res->[0] = 304;
$h->remove($_) for qw( Content-Type Content-Length Content-Disposition );
- $res->[2] = [];
+ if ($res->[2]) {
+ $res->[2] = [];
+ }
+ else {
+ my $done;
+ return sub {
+ unless ($done) {
+ return q{};
+ }
+ $done = 1;
+ return defined $_[0] ? q{} : undef;
+ };
+ }
}
});
}
View
5 t/Plack-Middleware/conditionalget_writer.t
@@ -29,13 +29,12 @@ test_psgi $handler, sub {
is $res->code, 200, 'Response HTTP status';
is $res->content, 'klingklangklong', 'Response content';
- # the middleware does not support streaming interface but make it at least not die
$res = $cb->( GET
"http://localhost/streaming-klingklangklong",
'If-None-Match' => 'DEADBEEF'
);
- is $res->code, 200, 'Response HTTP status';
- is $res->content, 'klingklangklong', 'Response content';
+ is $res->code, 304, 'Response HTTP status';
+ ok(!$res->content);
};
done_testing;

0 comments on commit c1e5684

Please sign in to comment.
Something went wrong with that request. Please try again.