[Catalyst] Patch for Catalyst::Engine::Apache

Bill Moseley moseley at hank.org
Fri May 19 21:28:29 CEST 2006


Andy, here's an updated patch that changes from testing port == 443
to port =~ /443/.  This allows the back-end Catalyst server to
listen on two ports.  The the front-end reverse proxy can connect to,
say, 8080 for non-SSL connections and 8443 for SSL connections.

Think that's a good way to go?


-- 
Bill Moseley
moseley at hank.org

-------------- next part --------------
Index: lib/Catalyst/Engine/Apache.pm
===================================================================
--- lib/Catalyst/Engine/Apache.pm	(revision 4064)
+++ lib/Catalyst/Engine/Apache.pm	(working copy)
@@ -44,7 +44,8 @@
         $c->request->secure(1);
     }
 
-    if ( $self->apache->get_server_port == 443 ) {
+
+    if ( $self->apache->get_server_port =~ /443/ ) {
         $c->request->secure(1);
     }
 }
@@ -69,11 +70,10 @@
 
 sub prepare_path {
     my ( $self, $c ) = @_;
-    
-    my $scheme = $c->request->secure ? 'https' : 'http';
+
     my $host   = $self->apache->hostname || 'localhost';
     my $port   = $self->apache->get_server_port;
-    
+
     # If we are running as a backend proxy, get the true hostname
     PROXY_CHECK:
     {
@@ -84,11 +84,22 @@
         last PROXY_CHECK unless $c->request->header( 'X-Forwarded-Host' );
 
         $host = $c->request->header( 'X-Forwarded-Host' );
-        # backend could be on any port, so
-        # assume frontend is on the default port
-        $port = $c->request->secure ? 443 : 80;
+
+        if ( $c->request->header('X-Is-SSL') ) {
+            $c->request->secure(1);
+
+        } elsif ( $host =~ /^(.+):(\d+)$/ ) {
+            $host = $1;
+            $port = $2;
+            $c->request->secure(1) if $port =~ /443/;
+        } else {
+            # backend could be on any port, so
+            # assume frontend is on the default port
+            $port = $c->request->secure ? 443 : 80;
+        }
     }
 
+
     my $base_path = q{};
 
     # Are we running in a non-root Location block?
@@ -96,15 +107,16 @@
     if ( $location && $location ne '/' ) {
         $base_path = $location;
     }
-    
+
     # Are we an Apache::Registry script? Why anyone would ever want to run
     # this way is beyond me, but we'll support it!
     if ( $self->apache->filename && -f $self->apache->filename && -x _ ) {
         $base_path .= $ENV{SCRIPT_NAME};
     }
-    
+
+
     my $uri = URI->new;
-    $uri->scheme($scheme);
+    $uri->scheme( $c->request->secure ? 'https' : 'http' );
     $uri->host($host);
     $uri->port($port);
     $uri->path( $self->apache->uri );
Index: Changes
===================================================================
--- Changes	(revision 4064)
+++ Changes	(working copy)
@@ -1,5 +1,18 @@
 This file documents the revision history for Catalyst::Engine::Apache.
 
+1.08
+        - Changed to extract port from X-Forwarded-Host.  And if extracted
+        port =~ /443/ then is considered a secure connection.  That allows
+        for using, say, 8443 in a front-end.  This is only helpful for testing
+        since a SSL connection on the standard port will not normally include
+        the port number in the X-Forwarded-Host header.
+
+        - Changed test for connecting port == 443 to port =~ /443/.
+        This allows setting up the Catalyst server to listen to two ports
+        (e.g. 3080 and 3444) for the front end server to connect to.
+        Catalyst can determine if it's a SSL connection by which port the
+        front end server connected to.
+
 1.07    2006-02-17 17:00:00
         - Fixed bug: Can't locate object method "FIRSTKEY" via package
           "APR::Table" when running under mod_perl 2.0.2.


More information about the Catalyst mailing list