[Catalyst-commits] r13522 - Catalyst-Runtime/5.80/branches/https_on_port_80/lib/Catalyst/Engine

dduncan at dev.catalyst.perl.org dduncan at dev.catalyst.perl.org
Wed Aug 25 05:55:06 GMT 2010


Author: dduncan
Date: 2010-08-25 06:55:06 +0100 (Wed, 25 Aug 2010)
New Revision: 13522

Modified:
   Catalyst-Runtime/5.80/branches/https_on_port_80/lib/Catalyst/Engine/CGI.pm
Log:
update Engine::CGI to support HTTPS on port 80, HTTP on 443, for CGI/FastCGI when not proxying

Modified: Catalyst-Runtime/5.80/branches/https_on_port_80/lib/Catalyst/Engine/CGI.pm
===================================================================
--- Catalyst-Runtime/5.80/branches/https_on_port_80/lib/Catalyst/Engine/CGI.pm	2010-08-25 05:49:36 UTC (rev 13521)
+++ Catalyst-Runtime/5.80/branches/https_on_port_80/lib/Catalyst/Engine/CGI.pm	2010-08-25 05:55:06 UTC (rev 13522)
@@ -106,6 +106,9 @@
         $request->address($ip);
         if ( defined $ENV{HTTP_X_FORWARDED_PORT} ) {
             $ENV{SERVER_PORT} = $ENV{HTTP_X_FORWARDED_PORT};
+            if ( $ENV{SERVER_PORT} == 443 ) {
+                $request->secure(1);
+            }
         }
     }
 
@@ -119,9 +122,6 @@
         $request->secure(1);
     }
 
-    if ( $ENV{SERVER_PORT} == 443 ) {
-        $request->secure(1);
-    }
     binmode(STDOUT); # Ensure we are sending bytes.
 }
 
@@ -215,9 +215,15 @@
     my $uri_class = "URI::$scheme";
 
     # HTTP_HOST will include the port even if it's 80/443
-    $host =~ s/:(?:80|443)$//;
-
-    if ( $port !~ /^(?:80|443)$/ && $host !~ /:/ ) {
+    if ($host =~ s/:(.*)$//) {
+        $port = $1;  # since $ENV{SERVER_PORT} may be missing or wrong
+    }
+    if ($port == 80 and !$c->request->secure or $port == 443 and $c->request->secure) {
+        # The actual port matches the default port for the security status,
+        # so leave $host without a :$port.
+    }
+    else {
+        # The actual port doesn't match the default port for the security status.
         $host .= ":$port";
     }
 




More information about the Catalyst-commits mailing list