Changed default match to use path instead of result
[catagits/Catalyst-Runtime.git] / lib / Catalyst / Engine.pm
index ba408f9..095c4ff 100644 (file)
@@ -7,6 +7,7 @@ use Data::Dumper;
 use HTML::Entities;
 use HTTP::Body;
 use HTTP::Headers;
+use URI::QueryParam;
 
 # input position and length
 __PACKAGE__->mk_accessors(qw/read_position read_length/);
@@ -43,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') ) {
+        while ( !$c->response->body->eof() ) {
+            $c->response->body->read( my $buffer, $CHUNKSIZE );
+            $self->write( $c, $buffer );
+        }
+        $c->response->body->close();
+    }
+    else {
+        $self->write( $c, $c->response->body );
+    }
 }
 
 =item $self->finalize_cookies($c)
@@ -333,7 +342,19 @@ sub prepare_path { }
 
 =cut
 
-sub prepare_query_parameters { }
+sub prepare_query_parameters {
+    my ( $self, $c, $query_string ) = @_;
+
+    # replace semi-colons
+    $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];
+    }
+}
 
 =item $self->prepare_read($c)
 
@@ -373,6 +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];
     }
 }