From: Christian Hansen Date: Tue, 22 Mar 2005 23:16:08 +0000 (+0000) Subject: reworked base and path handling X-Git-Tag: 5.7099_04~1731 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Runtime.git;a=commitdiff_plain;h=8b4483b384270e6e6a7e78bfb2fbdbefdf7b72f4 reworked base and path handling --- diff --git a/lib/Catalyst/Engine/CGI.pm b/lib/Catalyst/Engine/CGI.pm index 1588717..b48cf2f 100644 --- a/lib/Catalyst/Engine/CGI.pm +++ b/lib/Catalyst/Engine/CGI.pm @@ -159,19 +159,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 diff --git a/lib/Catalyst/Test.pm b/lib/Catalyst/Test.pm index 3265da3..4525468 100644 --- a/lib/Catalyst/Test.pm +++ b/lib/Catalyst/Test.pm @@ -92,6 +92,7 @@ sub request { $ENV{HTTP_HOST} ||= $request->uri->host || 'localhost'; $ENV{QUERY_STRING} ||= $request->uri->query || ''; $ENV{REQUEST_METHOD} ||= $request->method; + $ENV{PATH_INFO} ||= $request->uri->path || '/'; $ENV{SCRIPT_NAME} ||= $request->uri->path || '/'; $ENV{SERVER_NAME} ||= $request->uri->host || 'localhost'; $ENV{SERVER_PORT} ||= $request->uri->port;