Added support for IO::Handle in $c->res->body
Sebastian Riedel [Thu, 20 Oct 2005 15:46:16 +0000 (15:46 +0000)]
lib/Catalyst.pm
lib/Catalyst/Engine.pm

index e9fed2e..c904ed3 100644 (file)
@@ -1626,6 +1626,8 @@ Andy Wardley
 
 Andreas Marienborg
 
+Andrew Bramble
+
 Andrew Ford
 
 Andrew Ruthven
index b5cba7b..7b8fe91 100644 (file)
@@ -44,8 +44,16 @@ Finalize body.  Prints the response output.
 
 sub finalize_body {
     my ( $self, $c ) = @_;
-
-    $self->write( $c, $c->response->output );
+    if ( ref $c->response->body && $c->response->body->can('read') ) {
+        my $buffer;
+        while ( !$c->response->body->eof() ) {
+            $c->response->body->read( $buffer, $CHUNKSIZE );
+            $self->write( $c, $buffer );
+        }
+    }
+    else {
+        $self->write( $c, $c->response->output );
+    }
 }
 
 =item $self->finalize_cookies($c)
@@ -341,10 +349,10 @@ sub prepare_query_parameters {
     $query_string =~ s/;/&/g;
 
     my $u = URI->new( '', 'http' );
-        $u->query( $query_string );
-        for my $key ( $u->query_param ) {
-        my @vals = $u->query_param($key);  
-        $c->request->query_parameters->{$key} = @vals > 1 ? [@vals] : $vals[0];  
+    $u->query($query_string);
+    for my $key ( $u->query_param ) {
+        my @vals = $u->query_param($key);
+        $c->request->query_parameters->{$key} = @vals > 1 ? [@vals] : $vals[0];
     }
 }
 
@@ -386,11 +394,11 @@ sub prepare_uploads {
             push @uploads, $u;
         }
         $c->request->uploads->{$name} = @uploads > 1 ? \@uploads : $uploads[0];
-        
+
         # support access to the filename as a normal param
         my @filenames = map { $_->{filename} } @uploads;
-        $c->request->parameters->{$name} 
-            = @filenames > 1 ? \@filenames : $filenames[0];
+        $c->request->parameters->{$name} =
+          @filenames > 1 ? \@filenames : $filenames[0];
     }
 }