[mod_python] Help with mod_python, mod_proxy & cookies

Marc Boorshtein mboorshtein at gmail.com
Wed Jan 24 18:12:15 EST 2007


All,

I am trying to figure out a way to use mod python to change the Cookie
header of a request and then pass the request off to mod_proxy.  When
the response comes I wish to be able to adjust any Set-Cookie headers
in the response back to the client.  I did something similar in
mod_perl using filters and am assuming it would be a similar process.
I wrote a quick input filter to trace the data going through the
filter and found a few issues:

1.  When I have a ProxyPass in my httpd config, apache doesn't fire my filter
2.  When I remove the ProxyPass rule my filter fires, but no data
seems to be going through it
3.  When I specify AddInputFilter, is there anyway to have it apply
globally (as opposed to for a particular file extension)?

Here's my code:

from mod_python import apache

def inputfilter(filter):
    apache.log_error('in filter');
    s = filter.read()
    apache.log_error('begin data');
    while s:
        apache.log_error('data : ' + s);
        filter.write(s.upper())
        s = filter.read()
    apache.log_error('end data');

    if s is None:
        filter.close()

Here's my apache config:
<VirtualHost *>
  PythonDebug On
  PythonPath "sys.path + ['/home/mlb/workspace/Python\ CookieFilter/src']"
  PythonInputFilter CookieFilterInbound COOKIEINBOUND
  AddInputFilter COOKIEINBOUND .html
   ProxyPass / http://localhost:8080/
</VirtualHost>

Here's my log:

[Wed Jan 24 16:28:25 2007] [notice] Apache/2.2.3 (Fedora) configured
-- resuming normal operations
[Wed Jan 24 16:28:28 2007] [notice] mod_python: (Re)importing module
'CookieFilterInbound'
[Wed Jan 24 16:28:28 2007] [error] in filter
[Wed Jan 24 16:28:28 2007] [error] begin data
[Wed Jan 24 16:28:28 2007] [error] end data
[Wed Jan 24 16:28:28 2007] [error] [client 127.0.0.1] File does not
exist: /var/www/html/showcookie.html
[Wed Jan 24 16:28:28 2007] [error] in filter
[Wed Jan 24 16:28:28 2007] [error] begin data
[Wed Jan 24 16:28:28 2007] [error] end data
[Wed Jan 24 16:29:23 2007] [notice] caught SIGTERM, shutting down

Any help would be greatly appreciated.

Thanks
Marc


More information about the Mod_python mailing list