set body io-handle as the PSGI spec requires, and handle the backcompat case
John Napiorkowski [Mon, 30 Dec 2013 15:26:43 +0000 (09:26 -0600)]
lib/Catalyst/Engine.pm

index e2f77a2..349bc43 100644 (file)
@@ -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.