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

Merged
merged 1 commit into from May 17, 2012
Jump to file or symbol
Failed to load files and symbols.
+15 −5
Split
@@ -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;
+ };
+ }
}
});
}
@@ -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;