X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FCatalyst%2FEngine%2FCGI.pm;h=ef293578471534688043c3b2f8e91d183f10cdb8;hb=4612bc16fae23b7ee932e184db21f0d975981d86;hp=1efa954631460b6525ea2c48d8fea6a76c4560c4;hpb=23f9d93414eadb11350029f13b51841d8309363b;p=catagits%2FCatalyst-Runtime.git diff --git a/lib/Catalyst/Engine/CGI.pm b/lib/Catalyst/Engine/CGI.pm index 1efa954..ef29357 100644 --- a/lib/Catalyst/Engine/CGI.pm +++ b/lib/Catalyst/Engine/CGI.pm @@ -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 object. @@ -65,7 +61,7 @@ This config parameter contains the C object. =head1 OVERLOADED METHODS -This class overloads some methods from C. +This class overloads some methods from C. =over 4 @@ -75,7 +71,7 @@ This class overloads some methods from C. 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); @@ -106,6 +102,16 @@ sub finalize_output { print $c->response->output; } +=item $c->prepare_connection + +=cut + +sub prepare_connection { + my $c = shift; + $c->req->hostname( $c->cgi->remote_host ); + $c->req->address( $c->cgi->remote_addr ); +} + =item $c->prepare_cookies Sets up cookies. @@ -125,6 +131,8 @@ sub prepare_headers { ( my $field = $header ) =~ s/^HTTPS?_//; $c->req->headers->header( $field => $c->cgi->http($header) ); } + $c->req->headers->header( 'Content-Type' => $c->cgi->content_type ); + $c->req->headers->header( 'Content-Length' => $c->cgi->content_length ); } =item $c->prepare_parameters @@ -133,6 +141,9 @@ sub prepare_headers { sub prepare_parameters { my $c = shift; + + $c->cgi->parse_query_string; + my %vars = $c->cgi->Vars; while ( my ( $key, $value ) = each %vars ) { my @values = split "\0", $value; @@ -147,19 +158,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 @@ -175,6 +195,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' ), @@ -183,6 +204,10 @@ sub prepare_uploads { } } +=item $c->run + +=cut + sub run { shift->handler } =back