[Catalyst] Catalyst::Engine::CGI::prepare_path port
Jim Spath
jspath at pangeamedia.com
Thu Feb 15 15:39:17 GMT 2007
Jim Spath wrote:
> I was wondering why Catalyst::Engine::CGI::prepare_path() ignores the
> port in the Host header and instead uses $ENV{SERVER_PORT}.
>
> my $scheme = $c->request->secure ? 'https' : 'http';
> my $host = $ENV{HTTP_HOST} || $ENV{SERVER_NAME};
> my $port = $ENV{SERVER_PORT} || 80;
> ...
> my $uri = $uri_proto->clone;
> $uri->scheme($scheme);
> $uri->host($host);
> $uri->port($port);
>
> The reason I ask is that we are running a Pound load balancer that
> listens on port 80, but passes requests off to the Catalyst machines on
> port 81. Pound does not pass an X_FORWARDED_HOST header, instead it
> appends the port to the original Host header, and passes that through.
>
> If Catalyst::Engine::CGI allowed URI to retrieve the port from the Host
> header, which is allowed in the HTTP 1.1 spec, my problem would be solved:
>
> $uri->host($host);
> $uri->port($port) unless $uri->port;
>
> Does this solution make sense? I could provide a patch if so... it's
> obviously a tiny change. I guess the only thing I am uncertain of is if
> there are situations where we do not want to use a port from the Host
> header.
>
> - Jim
I just realized that URI sets the port to 80 by default, so my change as
proposed above would not work correctly, but something like the
following could also work:
if ($host =~ /^(.+):(\d+)$/) {
$host = $1;
$port = $2;
}
More information about the Catalyst
mailing list