[Catalyst-commits] r12598 - in Catalyst-Runtime/5.80/branches/psgi: . lib/Catalyst

rafl at dev.catalyst.perl.org rafl at dev.catalyst.perl.org
Sun Jan 10 17:03:50 GMT 2010


Author: rafl
Date: 2010-01-10 17:03:50 +0000 (Sun, 10 Jan 2010)
New Revision: 12598

Modified:
   Catalyst-Runtime/5.80/branches/psgi/Makefile.PL
   Catalyst-Runtime/5.80/branches/psgi/lib/Catalyst/Engine.pm
Log:
Start supporting running behind reverse proxies again.

Modified: Catalyst-Runtime/5.80/branches/psgi/Makefile.PL
===================================================================
--- Catalyst-Runtime/5.80/branches/psgi/Makefile.PL	2010-01-10 17:03:32 UTC (rev 12597)
+++ Catalyst-Runtime/5.80/branches/psgi/Makefile.PL	2010-01-10 17:03:50 UTC (rev 12598)
@@ -54,6 +54,7 @@
 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';

Modified: Catalyst-Runtime/5.80/branches/psgi/lib/Catalyst/Engine.pm
===================================================================
--- Catalyst-Runtime/5.80/branches/psgi/lib/Catalyst/Engine.pm	2010-01-10 17:03:32 UTC (rev 12597)
+++ Catalyst-Runtime/5.80/branches/psgi/lib/Catalyst/Engine.pm	2010-01-10 17:03:50 UTC (rev 12598)
@@ -12,6 +12,8 @@
 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 _build_psgi_app {
     my ($self, $app, @args) = @_;
-    return sub {
+
+    my $psgi_app = sub {
         my ($env) = @_;
 
         return sub {
@@ -765,6 +768,18 @@
             $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 {




More information about the Catalyst-commits mailing list