[Catalyst] Catalyst::Engine::CGI::prepare_path port

Jim Spath jspath at pangeamedia.com
Thu Feb 15 15:16:58 GMT 2007


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



More information about the Catalyst mailing list