I needed the forwarded host on a backend mod_perl server from mod_proxy under Apache 1.3. The
mod_perl docs show how to accomplish this for IP by parsing the X-Forwarded-For header in startup.pl and setting $r->connection->remote_ip to that value. To avoid
patching mod_proxy I added a few lines to mod_perl's My::ProxyRemoteAddr that sets $r->header_in('Host') to the value of the X-Forwarded-Host header.
It works but a question remains since I can't find examples online of sane people doing it this way. Is this a sound approach? If not, please correct me. If so, maybe the already very excellent mod_perl docs could benefit by adding this information. Thanks for your consideration.
sub My::ProxyRemoteAddr ($) {
my $r = shift;
return Apache::Constants::OK
unless ($r->connection->remote_ip eq "127.0.0.1")
and $r->header_in('X-Forwarded-For')
and $r->header_in('X-Forwarded-Host');
if (my ($ip) = $r->header_in('X-Forwarded-For') =~ /([^,\s]+)$/) {
$r->connection->remote_ip($ip);
}
if (my ($fh) = $r->header_in('X-Forwarded-Host') =~ /([^,\s]+)$/) {
$r->header_in('Host',$fh);
}
return Apache::Constants::OK;
}
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.