Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

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

Merged
merged 1 commit into from

2 participants

@wreis

No description provided.

@miyagawa

I will merge this time, but it would be nice if your patch can coordinate with the rest of the code when it comes to the indent level and so on.

@miyagawa miyagawa merged commit d7b54a6 into plack:master
@ssmccoy ssmccoy referenced this pull request from a commit
Commit has since been removed from the repository and is no longer available.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Mar 27, 2012
  1. Add support for streaming to P::M::ConditionalGET

    Wallace Reis authored
This page is out of date. Refresh to see the latest.
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;
Something went wrong with that request. Please try again.