From: Andy Grundman Date: Mon, 5 Dec 2005 16:40:56 +0000 (+0000) Subject: Re-added REDIRECT_URL support with tests X-Git-Tag: 5.7099_04~798 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Runtime.git;a=commitdiff_plain;h=0bcb98c7b698a94fe472f92509beb55f30010f18 Re-added REDIRECT_URL support with tests --- diff --git a/Changes b/Changes index 1d087d5..b5b4831 100644 --- a/Changes +++ b/Changes @@ -1,5 +1,9 @@ This file documents the revision history for Perl extension Catalyst. +5.62 + - Added REDIRECT_URL support for applications running behind + a RewriteRule in Apache. (Carl Franks) + 5.61 2005-12-02 00:00:00 - Fixed ExtUtils::AutoInstall Bootstrap Code in Makefile.PL diff --git a/lib/Catalyst/Engine/CGI.pm b/lib/Catalyst/Engine/CGI.pm index d2d041e..9f6698d 100644 --- a/lib/Catalyst/Engine/CGI.pm +++ b/lib/Catalyst/Engine/CGI.pm @@ -112,7 +112,14 @@ sub prepare_path { my $scheme = $c->request->secure ? 'https' : 'http'; my $host = $ENV{HTTP_HOST} || $ENV{SERVER_NAME}; my $port = $ENV{SERVER_PORT} || 80; - my $base_path = $ENV{SCRIPT_NAME} || '/'; + my $base_path; + if ( exists $ENV{REDIRECT_URL} ) { + $base_path = $ENV{REDIRECT_URL}; + $base_path =~ s/$ENV{PATH_INFO}$//; + } + else { + $base_path = $ENV{SCRIPT_NAME} || '/'; + } # If we are running as a backend proxy, get the true hostname PROXY_CHECK: diff --git a/t/conf/extra.conf.in b/t/conf/extra.conf.in index 3daa2a0..fff041d 100644 --- a/t/conf/extra.conf.in +++ b/t/conf/extra.conf.in @@ -1,11 +1,19 @@ # CGI ScriptAlias /cgi/ @ServerRoot@/tmp/TestApp/script/testapp_cgi.pl/ + + # REDIRECT_URL test + + + RewriteEngine on + RewriteRule /rewrite/(.*) /cgi/$1 + + # FastCGI FastCgiIpcDir @ServerRoot@/tmp/tmp - FastCgiServer @ServerRoot@/tmp/TestApp/script/testapp_fastcgi.pl -idle-timeout 300 -processes 5 + FastCgiServer @ServerRoot@/tmp/TestApp/script/testapp_fastcgi.pl -idle-timeout 300 -processes 1 ScriptAlias /fastcgi/ @ServerRoot@/tmp/TestApp/script/testapp_fastcgi.pl/ diff --git a/t/optional_apache-cgi-rewrite.pl b/t/optional_apache-cgi-rewrite.pl new file mode 100755 index 0000000..4007330 --- /dev/null +++ b/t/optional_apache-cgi-rewrite.pl @@ -0,0 +1,59 @@ +#!perl + +# Run all tests against CGI mode under Apache +# +# Note, to get this to run properly, you may need to give it the path to your +# httpd.conf: +# +# perl t/optional/apache-cgi.pl -httpd_conf /etc/apache/httpd.conf + +use strict; +use warnings; + +use Apache::Test; +use Apache::TestRun (); + +use File::Path; +use File::Copy::Recursive; +use FindBin; +use IO::Socket; + +# clean up +rmtree "$FindBin::Bin/../t/tmp" if -d "$FindBin::Bin/../t/tmp"; + +# create a TestApp and copy the test libs into it +mkdir "$FindBin::Bin/../t/tmp"; +chdir "$FindBin::Bin/../t/tmp"; +system "$FindBin::Bin/../script/catalyst.pl TestApp"; +chdir "$FindBin::Bin/.."; +File::Copy::Recursive::dircopy( 't/lib', 't/tmp/TestApp/lib' ); + +# remove TestApp's tests so Apache::Test doesn't try to run them +rmtree 't/tmp/TestApp/t'; + +$ENV{CATALYST_SERVER} = 'http://localhost:8529/rewrite'; + +Apache::TestRun->new->run(@ARGV); + +# clean up if the server has shut down +# this allows the test files to stay around if the user ran -start-httpd +if ( !check_port( 'localhost', 8529 ) ) { + rmtree "$FindBin::Bin/../t/tmp" if -d "$FindBin::Bin/../t/tmp"; +} + +sub check_port { + my ( $host, $port ) = @_; + + my $remote = IO::Socket::INET->new( + Proto => "tcp", + PeerAddr => $host, + PeerPort => $port + ); + if ($remote) { + close $remote; + return 1; + } + else { + return 0; + } +}