From: John Napiorkowski Date: Mon, 30 Dec 2013 15:26:43 +0000 (-0600) Subject: set body io-handle as the PSGI spec requires, and handle the backcompat case X-Git-Tag: 5.90060~33 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=568942951f418af5fbd97e4a94400adbb6aa19ff;p=catagits%2FCatalyst-Runtime.git set body io-handle as the PSGI spec requires, and handle the backcompat case --- diff --git a/lib/Catalyst/Engine.pm b/lib/Catalyst/Engine.pm index e2f77a2..349bc43 100644 --- a/lib/Catalyst/Engine.pm +++ b/lib/Catalyst/Engine.pm @@ -85,9 +85,26 @@ sub finalize_body { ## We need to figure out what kind of body we have... my $body = $res->body; if(defined $body) { - if(blessed($body) && $body->can('read') or ref($body) eq 'GLOB') { - # Body is a filehandle like thingy. We can jusrt send this along - # to plack without changing it. + if( + (blessed($body) && $body->can('getline')) + or ref($body) eq 'GLOB' + ) { + # Body is an IO handle that meets the PSGI spec + } elsif(blessed($body) && $body->can('read')) { + # In the past, Catalyst only looked for read not getline. It is very possible + # that one might have an object that respected read but did not have getline. + # As a result, we need to handle this case for backcompat. + + # We will just do the old loop for now but someone could write a proxy + # object to wrap getline and proxy read + my $got; + do { + $got = read $body, my ($buffer), $CHUNKSIZE; + $got = 0 unless $self->write($c, $buffer ); + } while $got > 0; + + close $body; + return; } else { # Looks like for backcompat reasons we need to be able to deal # with stringyfiable objects.