added synopsis to Engine subclassed and documented a couple of methods to make podcov...
[catagits/Catalyst-Runtime.git] / lib / Catalyst / Engine / CGI.pm
index 1a9d04a..6946e55 100644 (file)
@@ -53,10 +53,6 @@ useful in production applications, but it may be helpful for development.
 
 =over 4
 
-=item $c->run
-
-To be called from a CGI script to start the Catalyst application.
-
 =item $c->cgi
 
 This config parameter contains the C<CGI::Simple> object.
@@ -75,7 +71,7 @@ This class overloads some methods from C<Catalyst>.
 
 sub finalize_headers {
     my $c = shift;
-    my %headers = ( -nph => 1 );
+    my %headers;
     $headers{-status} = $c->response->status if $c->response->status;
     for my $name ( $c->response->headers->header_field_names ) {
         $headers{"-$name"} = $c->response->headers->header($name);
@@ -159,19 +155,28 @@ sub prepare_parameters {
 
 sub prepare_path {
     my $c = shift;
-    $c->req->path( $c->cgi->url( -absolute => 1, -path_info => 1 ) );
-    my $loc = $c->cgi->url( -absolute => 1 );
-    no warnings 'uninitialized';
-    $c->req->{path} =~ s/^($loc)?\///;
-    $c->req->{path} .= '/' if $c->req->path eq $loc;
-    my $base = $c->cgi->url;
-    if ( $ENV{CATALYST_TEST} ) {
-        my $script = $c->cgi->script_name;
-        $base =~ s/$script$//i;
+
+    my $base;
+    {
+        my $scheme = $ENV{HTTPS} ? 'https' : 'http';
+        my $host   = $ENV{HTTP_HOST} || $ENV{SERVER_NAME};
+        my $port   = $ENV{SERVER_PORT} || 80;
+        my $path   = $ENV{SCRIPT_NAME} || '/';
+
+        $base = URI->new;
+        $base->scheme($scheme);
+        $base->host($host);
+        $base->port($port);
+        $base->path($path);
+
+        $base = $base->canonical->as_string;
     }
-    $base = URI->new($base);
-    $base->path('/') if ( $ENV{CATALYST_TEST} || !$base->path );
-    $c->req->base( $base->as_string );
+
+    my $path = $ENV{PATH_INFO} || '/';
+    $path =~  s/^\///;
+
+    $c->req->base($base);
+    $c->req->path($path);
 }
 
 =item $c->prepare_request
@@ -187,6 +192,7 @@ sub prepare_request { shift->cgi( CGI::Simple->new ) }
 sub prepare_uploads {
     my $c = shift;
     for my $name ( $c->cgi->upload ) {
+        next unless defined $name;
         $c->req->uploads->{$name} = {
             fh   => $c->cgi->upload($name),
             size => $c->cgi->upload_info( $name, 'size' ),
@@ -195,6 +201,10 @@ sub prepare_uploads {
     }
 }
 
+=item $c->run
+
+=cut
+
 sub run { shift->handler }
 
 =back