httpd-dev mailing list archives

On 5/3/2012 5:57 PM, Chris Darroch wrote:
> I promise I won't
> be offended if anyone says it's a stupid hack and should never be
> committed, because, well, it is arguably a very stupid hack.
Actually, I think one could make the argument that all of the headers
set by mod_proxy should be just as configurable as any other header. I
have also faced situations with reverse proxies where a little
manipulation of the headers would save a lot of hassle.
I'm +1 to the idea of making something more configurable but -1 to the
idea of proceeding with an implementation for just this one case. I've
thought on several occasions that it would be quite valuable if
mod_headers could be run on the output headers of mod_proxy, but haven't
looked into the idea.
FWIW, this recipe seems to do the trick in my test case. Definitely not
"compliant" since it goobers up the other X-Forwarded-* headers, but
seems to accomplish your goal. It would also be fragile if multiple
X-Forwarded-For servers are prestend... you could tweak the regex to get
past that, though... ([^,\s]+) or something like that.
RewriteEngine On
RewriteCond %{HTTP:X-Forwarded-For} (.+)
RewriteRule .* - [E=XFWD:%1]
ProxyPreserveHost On
RequestHeader set Host %{XFWD}e env=XFWD
Sample request1:
HEAD /XFwdTest/ HTTP/1.1
Host: whatever.com
X-Forwarded-Host: somethingElse.com
Connection: close
And what showed up downstream:
HEAD /XFwdTest/ HTTP/1.1
Host: somethingElse.com
X-Forwarded-Host: somethingElse.com, somethingElse.com
X-Forwarded-For: 192.168.0.2
X-Forwarded-Server: testbed.com
Connection: Keep-Alive
Sample request2:
HEAD /XFwdTest/ HTTP/1.1
Host: whatever.com
Connection: close
And what showed up downstream:
HEAD /XFwdTest/ HTTP/1.1
Host: whatever.com
X-Forwarded-For: 192.168.0.2
X-Forwarded-Host: whatever.com
X-Forwarded-Server: testbed.com
Connection: Keep-Alive
--
Daniel Ruggeri