[mod_python] changing req.proxyreq on the fly

Graham Dumpleton grahamd at dscpl.com.au
Thu Mar 2 22:37:51 EST 2006


Bill Fraser wrote ..
> 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.

There are various members in the req object in mod_python which are
read only when they should be writable as well. I have been slowly identifying
them and making them writable as appropriate.

In the case of req.proxyreq, because it is an integer value, I think only
a one line change is required to make it writable.

Index: src/requestobject.c
===================================================================
--- src/requestobject.c (revision 382636)
+++ src/requestobject.c (working copy)
@@ -1675,7 +1675,7 @@
     {"main",       (getter)getmakeobj, NULL, "If subrequest, pointer to the main request", "main"},
     {"the_request", (getter)getreq_recmbr, NULL, "First line of request", "the_request"},
     {"assbackwards", (getter)getreq_recmbr, (setter)setreq_recmbr, "HTTP/0.9 \"simple\" request", "assbackwards"},
-    {"proxyreq",     (getter)getreq_recmbr, NULL, "A proxy request: one of apache.PROXYREQ_* values", "proxyreq"},
+    {"proxyreq",     (getter)getreq_recmbr, (setter)setreq_recmbr, "A proxy request: one of apache.PROXYREQ_* values", "proxyreq"},
     {"header_only",  (getter)getreq_recmbr, NULL, "HEAD request, as oppsed to GET", "header_only"},
     {"protocol",     (getter)getreq_recmbr, NULL, "Protocol as given to us, or HTTP/0.9", "protocol"},
     {"proto_num",    (getter)getreq_recmbr, NULL, "Protocol version. 1.1 = 1001", "proto_num"},

I haven't tested this yet though.

Can you possibly add an issue for this at:

  http://issues.apache.org/jira/browse/MODPYTHON

If not I'll add one later and include your email.

Graham


More information about the Mod_python mailing list