From: Florian Ragwitz Date: Sun, 10 Jan 2010 17:03:50 +0000 (+0000) Subject: Start supporting running behind reverse proxies again. X-Git-Tag: 5.89000~54 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Runtime.git;a=commitdiff_plain;h=c2f4a965484d7f564f72dca3e3c5fb262d896fa9 Start supporting running behind reverse proxies again. --- diff --git a/Makefile.PL b/Makefile.PL index 1f9fb0b..0ea5621 100644 --- a/Makefile.PL +++ b/Makefile.PL @@ -54,6 +54,7 @@ requires 'MooseX::Types'; requires 'MooseX::Types::Common::Numeric'; requires 'String::RewritePrefix' => '0.004'; # Catalyst::Utils::resolve_namespace requires 'Plack' => '0.9030'; +requires 'Plack::Middleware::ReverseProxy'; test_requires 'Class::Data::Inheritable'; test_requires 'Test::Exception'; diff --git a/lib/Catalyst/Engine.pm b/lib/Catalyst/Engine.pm index a9c3da3..4cc8c6d 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'; @@ -756,7 +758,8 @@ sub run { sub _build_psgi_app { my ($self, $app, @args) = @_; - return sub { + + my $psgi_app = sub { my ($env) = @_; return sub { @@ -765,6 +768,18 @@ sub _build_psgi_app { $app->handle_request(env => $env); }; }; + + $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; } sub _run_psgi_app {