Skip to content
This repository
Browse code

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

  • Loading branch information...
commit c1e56844446fff160cc257e257279415a8bcb658 1 parent b2f3ffb
Wallace Reis authored
15 lib/Plack/Middleware/ConditionalGET.pm
@@ -12,13 +12,24 @@ sub call {
12 12
13 13 $self->response_cb($res, sub {
14 14 my $res = shift;
15   - return unless $res->[2]; # do not support streaming interface
16 15
17 16 my $h = Plack::Util::headers($res->[1]);
18 17 if ( $self->etag_matches($h, $env) || $self->not_modified_since($h, $env) ) {
19 18 $res->[0] = 304;
20 19 $h->remove($_) for qw( Content-Type Content-Length Content-Disposition );
21   - $res->[2] = [];
  20 + if ($res->[2]) {
  21 + $res->[2] = [];
  22 + }
  23 + else {
  24 + my $done;
  25 + return sub {
  26 + unless ($done) {
  27 + return q{};
  28 + }
  29 + $done = 1;
  30 + return defined $_[0] ? q{} : undef;
  31 + };
  32 + }
22 33 }
23 34 });
24 35 }
5 t/Plack-Middleware/conditionalget_writer.t
@@ -29,13 +29,12 @@ test_psgi $handler, sub {
29 29 is $res->code, 200, 'Response HTTP status';
30 30 is $res->content, 'klingklangklong', 'Response content';
31 31
32   - # the middleware does not support streaming interface but make it at least not die
33 32 $res = $cb->( GET
34 33 "http://localhost/streaming-klingklangklong",
35 34 'If-None-Match' => 'DEADBEEF'
36 35 );
37   - is $res->code, 200, 'Response HTTP status';
38   - is $res->content, 'klingklangklong', 'Response content';
  36 + is $res->code, 304, 'Response HTTP status';
  37 + ok(!$res->content);
39 38 };
40 39
41 40 done_testing;

0 comments on commit c1e5684

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