[mod_python] handler for any request

Volodya volodya at real.samuraj.org
Fri May 7 17:22:59 EST 2004


On Fri, May 07, 2004 at 11:27:21AM +0400, Alexey Nezhdanov wrote:
> Hello.
> I have an slightly unusual question:How I can set up apache to route _all_ 
> incoming requests to the same python handler irrelevantly of request itself.
> 
> I want to design a back-proxy server gathering all requests going to 
> particular web-server, requesting the interested information itself from the 
> "real" server and feeding the server answer back to client.
> 
> I.e. I wish for the
> http://192.168.0.1/script.py
> http://192.168.0.1/index.asp
> http://192.168.0.1/dlls/form.dll
> http://192.168.0.1/cgi-bin/script.pl
> and all other requests that are directed to 192.168.0.1:80 going to python 
> handler.
> 
> Is such scheme is possible with mod_python?

Try this:

.htaccess file:

AddHandler mod_python .py
SetHandler mod_python
PythonHandler proxy
PythonDebug On


proxy.py file:

from mod_python import apache

def handler(req):
    req.content_type = "text/plain"
    req.write(req.the_request)
    return apache.OK


i've placed boths file in /proxy directory under the documents root,
so when i address url 'http://SERVER/proxy/test/one/two?three=four&five=six'
the output is:

GET /proxy/test/one/two?three=four&five=six HTTP/1.1

So proxying GET-requests is pretty simple. With POST-methods You'll have
more work to do.



More information about the Mod_python mailing list