X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FCatalyst.pm;h=6c1ef1eb4d65a218b74a351d440be4fda3d25ed8;hb=7e58c6275aeae6b53fb5be463fe1defbd31b7295;hp=39962a67863e00383200c76658afc49f9229c42e;hpb=a6fb59b76c87d2339fc7b837e492f2e17fa5f841;p=catagits%2FCatalyst-Runtime.git diff --git a/lib/Catalyst.pm b/lib/Catalyst.pm index 39962a6..6c1ef1e 100644 --- a/lib/Catalyst.pm +++ b/lib/Catalyst.pm @@ -36,6 +36,7 @@ use Carp qw/croak carp shortmess/; use Try::Tiny; use Plack::Middleware::Conditional; use Plack::Middleware::ReverseProxy; +use Plack::Middleware::IIS6ScriptNameFix; BEGIN { require 5.008004; } @@ -2665,6 +2666,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 +2685,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,46 +2694,27 @@ 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, - builder => sub { + condition => $server_matches->(qr/^nginx/), + 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); - + my $script_name = $env->{SCRIPT_NAME}; + $env->{PATH_INFO} =~ s/^$script_name//g; return $to_wrap->($env); }; }, - condition => sub { - my ($env) = @_; - my $server = $env->{SERVER_SOFTWARE}; - return unless $server; - return $server =~ /IIS\/[6-9]\.[0-9]/ ? 1 : 0; - }, ); + # we're applying this unconditionally as the middleware itself already makes + # sure it doesn't fuck things up if it's not running under one of the right + # IIS versions + $psgi_app = Plack::Middleware::IIS6ScriptNameFix->wrap($psgi_app); + return $psgi_app; }