[Catalyst-commits] r11144 - in Catalyst-Runtime/5.80/trunk: lib
lib/Catalyst/Engine t/aggregate
jshirley at dev.catalyst.perl.org
jshirley at dev.catalyst.perl.org
Mon Aug 17 21:33:20 GMT 2009
Author: jshirley
Date: 2009-08-17 21:33:17 +0000 (Mon, 17 Aug 2009)
New Revision: 11144
Modified:
Catalyst-Runtime/5.80/trunk/lib/Catalyst.pm
Catalyst-Runtime/5.80/trunk/lib/Catalyst/Engine/CGI.pm
Catalyst-Runtime/5.80/trunk/t/aggregate/live_engine_request_headers.t
Log:
Adding and documented X-Forwarded-Port
Modified: Catalyst-Runtime/5.80/trunk/lib/Catalyst/Engine/CGI.pm
===================================================================
--- Catalyst-Runtime/5.80/trunk/lib/Catalyst/Engine/CGI.pm 2009-08-16 18:08:03 UTC (rev 11143)
+++ Catalyst-Runtime/5.80/trunk/lib/Catalyst/Engine/CGI.pm 2009-08-17 21:33:17 UTC (rev 11144)
@@ -67,6 +67,9 @@
# as 127.0.0.1. Select the most recent upstream IP (last in the list)
my ($ip) = $ENV{HTTP_X_FORWARDED_FOR} =~ /([^,\s]+)$/;
$request->address($ip);
+ if ( defined $ENV{HTTP_X_FORWARDED_PORT} ) {
+ $ENV{SERVER_PORT} = $ENV{HTTP_X_FORWARDED_PORT};
+ }
}
$request->hostname( $ENV{REMOTE_HOST} ) if exists $ENV{REMOTE_HOST};
@@ -134,6 +137,9 @@
# backend could be on any port, so
# assume frontend is on the default port
$port = $c->request->secure ? 443 : 80;
+ if ( $ENV{HTTP_X_FORWARDED_PORT} ) {
+ $port = $ENV{HTTP_X_FORWARDED_PORT};
+ }
}
# set the request URI
Modified: Catalyst-Runtime/5.80/trunk/lib/Catalyst.pm
===================================================================
--- Catalyst-Runtime/5.80/trunk/lib/Catalyst.pm 2009-08-16 18:08:03 UTC (rev 11143)
+++ Catalyst-Runtime/5.80/trunk/lib/Catalyst.pm 2009-08-17 21:33:17 UTC (rev 11144)
@@ -2674,6 +2674,18 @@
The host value for $c->req->base and $c->req->uri is set to the real
host, as read from the HTTP X-Forwarded-Host header.
+Additionally, you may be running your backend application on an insecure
+connection (port 80) while your frontend proxy is running under SSL. If there
+is a discrepancy in the ports, use the HTTP header C<X-Forwarded-Port> to
+tell Catalyst what port the frontend listens on. This will allow all URIs to
+be created properly.
+
+In the case of passing in:
+
+ X-Forwarded-Port: 443
+
+All calls to C<uri_for> will result in an https link, as is expected.
+
Obviously, your web server must support these headers for this to work.
In a more complex server farm environment where you may have your
Modified: Catalyst-Runtime/5.80/trunk/t/aggregate/live_engine_request_headers.t
===================================================================
--- Catalyst-Runtime/5.80/trunk/t/aggregate/live_engine_request_headers.t 2009-08-16 18:08:03 UTC (rev 11143)
+++ Catalyst-Runtime/5.80/trunk/t/aggregate/live_engine_request_headers.t 2009-08-17 21:33:17 UTC (rev 11144)
@@ -6,7 +6,7 @@
use FindBin;
use lib "$FindBin::Bin/../lib";
-use Test::More tests => 17;
+use Test::More tests => 18;
use Catalyst::Test 'TestApp';
use Catalyst::Request;
@@ -22,6 +22,7 @@
'X-Multiple' => [ 1 .. 5 ],
'X-Forwarded-Host' => 'frontend.server.com',
'X-Forwarded-For' => '192.168.1.1, 1.2.3.4',
+ 'X-Forwarded-Port' => 443
);
ok( my $response = request($request), 'Request' );
@@ -30,6 +31,7 @@
like( $response->content, qr/^bless\( .* 'Catalyst::Request' \)$/s, 'Content is a serialized Catalyst::Request' );
ok( eval '$creq = ' . $response->content, 'Unserialize Catalyst::Request' );
isa_ok( $creq, 'Catalyst::Request' );
+ ok( $creq->secure, 'Forwarded port sets securet' );
isa_ok( $creq->headers, 'HTTP::Headers', 'Catalyst::Request->headers' );
is( $creq->header('X-Whats-Cool'), $request->header('X-Whats-Cool'), 'Catalyst::Request->header X-Whats-Cool' );
More information about the Catalyst-commits
mailing list