X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Runtime.git;a=blobdiff_plain;f=lib%2FCatalyst.pm;h=39962a67863e00383200c76658afc49f9229c42e;hp=696fd5795e0d1e8753de58374086c1541cc8c86f;hb=a6fb59b76c87d2339fc7b837e492f2e17fa5f841;hpb=1f440f555345b577d87e1b7e159aaa24121318ca diff --git a/lib/Catalyst.pm b/lib/Catalyst.pm index 696fd57..39962a6 100644 --- a/lib/Catalyst.pm +++ b/lib/Catalyst.pm @@ -34,6 +34,8 @@ use Catalyst::EngineLoader; use utf8; use Carp qw/croak carp shortmess/; use Try::Tiny; +use Plack::Middleware::Conditional; +use Plack::Middleware::ReverseProxy; BEGIN { require 5.008004; } @@ -2642,7 +2644,7 @@ sub _setup_psgi_app { if -e $psgi_file; } - return $app->_wrapped_legacy_psgi_app; + return $app->_wrapped_legacy_psgi_app($app->psgi_app); } # Note - this is for back compatibility. Catalyst should not know or care about @@ -2650,10 +2652,10 @@ sub _setup_psgi_app { # use the ReverseProxy middleware yourself if you want it in a .psgi # file. sub _wrapped_legacy_psgi_app { - my ($app) = @_; + my ($app, $psgi_app) = @_; - return Plack::Middleware::Conditional->wrap( - $app->psgi_app, + $psgi_app = Plack::Middleware::Conditional->wrap( + $psgi_app, builder => sub { Plack::Middleware::ReverseProxy->wrap($_[0]) }, condition => sub { my ($env) = @_; @@ -2662,6 +2664,65 @@ sub _wrapped_legacy_psgi_app { || $app->config->{using_frontend_proxy}; }, ); + + # 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 + # + # Note that this has probably the same effect as + # Plack::Middleware::LighttpdScriptNameFix and we should switch to that if + # we can. + $psgi_app = Plack::Middleware::Conditional->wrap( + $psgi_app, + builder => sub { + my ($to_wrap) = @_; + return sub { + my ($env) = @_; + $env->{PATH_INFO} ||= delete $env->{SCRIPT_NAME}; + 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 { + 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); + }; + }, + condition => sub { + my ($env) = @_; + my $server = $env->{SERVER_SOFTWARE}; + return unless $server; + return $server =~ /IIS\/[6-9]\.[0-9]/ ? 1 : 0; + }, + ); + + return $psgi_app; } =head2 $c->psgi_app