Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Merge pull request #275 from wreis/conditionalget_streaming

Add support for streaming to P::M::ConditionalGET
  • Loading branch information...
commit d7b54a68a52c22905cc364ce366fc24e8114f88f 2 parents abf55db + c1e5684
Tatsuhiko Miyagawa authored May 16, 2012
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 notes on commit d7b54a6

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