X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FCatalyst.pm;h=dcc8c2b5bc176c72b5d9eabdd63cc3cc5ec395a3;hb=db522412c578a200f448706e80284ebcf942e53b;hp=9f25c7ef053f203e9f2644df06cbfa7d49f62367;hpb=d89b863eba721ed2ab337220d1e52cfd039a81fe;p=catagits%2FCatalyst-Runtime.git diff --git a/lib/Catalyst.pm b/lib/Catalyst.pm index 9f25c7e..dcc8c2b 100644 --- a/lib/Catalyst.pm +++ b/lib/Catalyst.pm @@ -2665,6 +2665,16 @@ sub _wrapped_legacy_psgi_app { }, ); + my $server_matches = sub { + my ($re) = @_; + return sub { + my ($env) = @_; + my $server = $env->{SERVER_SOFTWARE}; + return unless $server; + return $server =~ $re ? 1 : 0; + }; + }; + # If we're running under Lighttpd, swap PATH_INFO and SCRIPT_NAME # http://lists.scsys.co.uk/pipermail/catalyst/2006-June/008361.html # Thanks to Mark Blythe for this fix @@ -2674,7 +2684,8 @@ sub _wrapped_legacy_psgi_app { # we can. $psgi_app = Plack::Middleware::Conditional->wrap( $psgi_app, - builder => sub { + condition => $server_matches->(qr/lighttpd/), + builder => sub { my ($to_wrap) = @_; return sub { my ($env) = @_; @@ -2682,11 +2693,46 @@ sub _wrapped_legacy_psgi_app { return $to_wrap->($env); }; }, - condition => sub { - my ($env) = @_; - my $server = $env->{SERVER_SOFTWARE}; - return unless $server; - return $server =~ /lighttpd/ ? 1 : 0; + ); + + $psgi_app = Plack::Middleware::Conditional->wrap( + $psgi_app, + condition => $server_matches->(qr/^nginx/), + builder => sub { + my ($to_wrap) = @_; + return sub { + my ($env) = @_; + my $script_name = $env->{SCRIPT_NAME}; + $env->{PATH_INFO} =~ s/^$script_name//g; + return $to_wrap->($env); + }; + }, + ); + + $psgi_app = Plack::Middleware::Conditional->wrap( + $psgi_app, + condition => $server_matches->(qr/IIS\/[6-9]\.[0-9]/), + builder => sub { + my ($to_wrap) = @_; + return sub { + my ($env) = @_; + + my @script_name = split(m!/!, $env->{PATH_INFO}); + my @path_translated = split(m!/|\\\\?!, $env->{PATH_TRANSLATED}); + my @path_info; + + while ($script_name[$#script_name] eq $path_translated[$#path_translated]) { + pop(@path_translated); + unshift(@path_info, pop(@script_name)); + } + + unshift(@path_info, '', ''); + + $env->{PATH_INFO} = join('/', @path_info); + $env->{SCRIPT_NAME} = join('/', @script_name); + + return $to_wrap->($env); + }; }, );