[mod_python] changing req.proxyreq on the fly

Bill Fraser bill.fraser at gmail.com
Thu Mar 2 22:12:18 EST 2006


Hello, this is my first post to this list, and I'm rather new to
Python, so please excuse me if my question is a trivial one. :)

I'm using Apache2's mod_rewrite for a proxy system on my webserver,
and I've noticed that no matter what, mod_rewrite instructs mod_proxy
to add all the X-Forwarded-* headers, despite the fact that the proxy
request is forward proxy and not a reverse one. Looking at the Apache2
source, mod_proxy specifically mentions in the relevant comment block
that this should NOT be done for forward proxy requests (and in fact
they are messing up the application this is for), yet mod_rewrite will
ALWAYS add them, no matter what the nature of the proxy request is.

Looking further in the source, I found that the way to change this
behavior is to change the value of the r->proxyreq variable from
PROXYREQ_REVERSE (what mod_rewrite sets it to) to PROXYREQ_PROXY. A
nice thing about Python is its ability to attach itself to arbitrary
points in the request process, so I thought I could change this value.
No luck. req.proxyreq is marked as read-only.

Is there any other way to change the value of req.proxyreq? Is there
some obscure Apache setting that might do the same that I've somehow
missed? Yes, I know I could write an Apache module in C that would get
this done, but that's way more than I want to do. I might as well
recompile Apache with the section that adds the headers commented out.

The method I tried was to define a this method:

def fixuphandler(req):
    req.proxyreq = 1
    return apache.OK

and use this in a PythonFixupHandler Apache directive. This causes a
500 error and throws 'TypeError: attribute 'proxyreq' of 'mp_request'
objects is not writable'.

Thanks in advance,
-Bill



More information about the Mod_python mailing list