[Catalyst] Patch for Catalyst::Engine::Apache
Bill Moseley
moseley at hank.org
Fri May 19 02:26:16 CEST 2006
On Fri, Apr 28, 2006 at 04:01:27PM -0700, Bill Moseley wrote:
> Things seem to vanish on IRC, so here's a patch that looks for the
> port in the X-Forwarded-Host header. Also matches port =~ /443/ to
> allow for more than just port 433 for SSL connections.
Ack. Vanished here, too.
Andy, you around?
Index: lib/Catalyst/Engine/Apache.pm
===================================================================
--- lib/Catalyst/Engine/Apache.pm (revision 4064)
+++ lib/Catalyst/Engine/Apache.pm (working copy)
@@ -69,11 +69,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 +83,19 @@
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 ( $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 +103,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,10 @@
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.
+
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.
_______________________________________________
Catalyst mailing list
Catalyst at lists.rawmode.org
http://lists.rawmode.org/mailman/listinfo/catalyst
----- End forwarded message -----
--
Bill Moseley
moseley at hank.org
More information about the Catalyst
mailing list