X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FCatalyst%2FEngine.pm;h=ff7e5489b7e9685e214ba804b9f8c61716918600;hb=22a5833d436649391dc95877ca33f549308c6c3c;hp=a9c3da3b16b7a13a94432d8cb6f2bf7c70afdbd7;hpb=a1791811465a12062122c0bf4cb73c56a5d5fad2;p=catagits%2FCatalyst-Runtime.git diff --git a/lib/Catalyst/Engine.pm b/lib/Catalyst/Engine.pm index a9c3da3..ff7e548 100644 --- a/lib/Catalyst/Engine.pm +++ b/lib/Catalyst/Engine.pm @@ -12,6 +12,8 @@ use HTTP::Headers; use URI::QueryParam; use Moose::Util::TypeConstraints; use Plack::Loader; +use Plack::Middleware::Conditional; +use Plack::Middleware::ReverseProxy; use namespace::clean -except => 'meta'; @@ -535,7 +537,7 @@ sub prepare_path { my $query = $env->{QUERY_STRING} ? '?' . $env->{QUERY_STRING} : ''; my $uri = $scheme . '://' . $host . '/' . $path . $query; - $ctx->request->uri( bless \$uri, $uri_class ); + $ctx->request->uri( (bless \$uri, $uri_class)->canonical ); # set the base URI # base must end in a slash @@ -748,15 +750,15 @@ Start the engine. Implemented by the various engine classes. =cut sub run { - my ($self, $app, @args) = @_; - Carp::cluck("Run"); + my ($self, $app, $server, @args) = @_; # FIXME - Do something sensible with the options we're passed - $self->_run_psgi_app($self->_build_psgi_app($app, @args), @args); + $server->run($self->build_psgi_app($app, @args)); } -sub _build_psgi_app { +sub build_psgi_app { my ($self, $app, @args) = @_; - return sub { + + my $psgi_app = sub { my ($env) = @_; return sub { @@ -765,12 +767,18 @@ sub _build_psgi_app { $app->handle_request(env => $env); }; }; -} -sub _run_psgi_app { - my ($self, $psgi_app, @args); - # FIXME - Need to be able to specify engine and pass options.. - Plack::Loader->auto()->run($psgi_app); + $psgi_app = Plack::Middleware::Conditional->wrap( + $psgi_app, + condition => sub { + my ($env) = @_; + return if $app->config->{ignore_frontend_proxy}; + return $env->{REMOTE_ADDR} eq '127.0.0.1' || $app->config->{using_frontend_proxy}; + }, + builder => sub { Plack::Middleware::ReverseProxy->wrap($_[0]) }, + ); + + return $psgi_app; } =head2 $self->write($c, $buffer)