Skip Menu |

This queue is for tickets about the Catalyst-Engine-HTTP-Prefork CPAN distribution.

Report information
The Basics
Id: 41577
Status: open
Priority: 0/
Queue: Catalyst-Engine-HTTP-Prefork

People
Owner: Nobody in particular
Requestors: GRAF [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Important
Broken in: 0.50
Fixed in: (no value)



Subject: Fails with lighttpd as FE proxy
lighttpd runs www.myapp.org on IP 1.2.3.4 and proxies certain requests to a Catalyst app that runs with a standalone server on 1.2.3.5. While everything seem to work with C:E::HTTP, things break with C:E::HTTP::Prefork. It turns out, that under C:E::HTTP $c->request->uri returns http://www.myapp.org/, whereas under C:E::HTTP::Prefork $c->request->uri gives http://1.2.3.5/. C:E::CGI cares for environment variable HTTP_HOST, to catch the real local host name. This variable is set from the request header "Host" in C:E::HTTP, but not in C:E::HTTP::Prefork . The attached patch fixes this. It also offers options to drop superuser privileges and to chroot after listen is set up (haven't tested chroot though).
Subject: Catalyst-Engine-HTTP-Prefork-0.50.patch
Index: lib/Catalyst/Engine/HTTP/Prefork.pm =================================================================== --- lib/Catalyst/Engine/HTTP/Prefork.pm (revision 8804) +++ lib/Catalyst/Engine/HTTP/Prefork.pm (working copy) @@ -45,6 +45,9 @@ max_servers => $options->{max_servers} || 50, max_requests => $options->{max_requests} || 1000, leave_children_open_on_hup => $options->{restart_graceful} || 0, + user => $options->{user} || $ENV{UID}, + group => $options->{group} || $ENV{GID}, + defined $options->{'chroot'} ? ('chroot' => $options->{'chroot'}) : (), ); } @@ -135,6 +138,10 @@ if $headers->{'X-Forwarded-For'}; $ENV{HTTP_X_FORWARDED_HOST} = $headers->{'X-Forwarded-Host'} if $headers->{'X-Forwarded-Host'}; + $ENV{HTTP_X_FORWARDED_PROTO} = $headers->{'X-Forwarded-Proto'} + if $headers->{'X-Forwarded-Proto'}; + $ENV{HTTP_HOST} = $headers->{'Host'} + if $headers->{'Host'}; # Determine whether we will keep the connection open after the request my $connection = $headers->{Connection};
After testing with Apache I learned that lighttpd and Apache set different Host request-headers when acting as frontend proxies (lighttpd uses the one that comes from the client, while Apache uses the target web server's address which is 1.2.3.5 in the above example). Argh! The "using_frontend_proxy" config option together with patching either lighttpd (to make it create the X-Forwarded-Host header) or C:E::CGI (to honor lighttpd's X-Host header) fixes the problem. Still it would be good if C:E::HTTP::Prefork would set the same environment variables as C:E::HTTP.