[mod_python] Problem with mod_proxy + inputfilter + headers_in

Graham Dumpleton graham.dumpleton at gmail.com
Thu Apr 19 17:53:30 EDT 2007


You can't use a mod_python input filter to modify incoming headers. If
the changes to the headers aren't intended to influence the behaviour
of what Apache does during access, authentication, authorisation and
type checking phases, use a PythonFixupHandler to update any headers
to then be used by the actual response handler.

Note, provided you are using mod_python 3.3, you can actually use
mod_python to trigger the proxying as well. See:

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

Graham

On 20/04/07, indyone ;o) <indyone at gmail.com> wrote:
> Hi list,
>
> I'm trying to get the headers_in from the client, and after changing/adding
> some headers i would like to pass them to the backend server.
> I'm using Apache/2.0.55 (Win32) mod_python/3.1.3 Python/2.3.5
> The problem is that the headers are sent to the backend unchanged when using
> this simple input filter:
>
> def inputfilter(filter):
>
>     filter.req.headers_in['X-MyHeader'] = 'Test'
>     if filter.req.main is not None:
>         filter.pass_on()
>         return
>
>     filter.req.log_error('Start %s' % filter.req.uri)
>     s = filter.read()
>     while s:
>         filter.write(s)
>         s = filter.read()
>     if s is None:
>         filter.close()
>         filter.req.log_error('End %s' % filter.req.uri)
>
>     filter.req.log_error('%s' % filter.req.headers_in)
>
> and Apache logs:
>
> [Thu Apr 19 18:17:28 2007] [error] [client 127.0.0.1] Start /, referer:
> http://localhost/
> [Thu Apr 19 18:17:28 2007] [error] [client 127.0.0.1] End /, referer:
> http://localhost/
> [Thu Apr 19 18:17:28 2007] [error] [client 127.0.0.1] {'X-MyHeader': 'Test',
> 'X-Forwarded-Server': 'luna', 'X-Forwarded-Host': 'localhost',
> 'X-Forwarded-For': ' 127.0.0.1', 'Max-Forwards': '10', 'Cookie': 'wstyle=;
> __ac="YWRtaW46bWF0cml4";
> tree-s="eJzT0MgpMOQKVneEAKcAN19bda4CI67EkgJjLj0AegYHmA"',
> 'Referer': ' http://localhost/', 'Accept-Charset':
> 'ISO-8859-7,utf-8;q=0.7,*;q=0.7', 'Accept-Encoding': 'gzip,deflate',
> 'Accept-Language': 'el,en-us;q=0.7 ,en;q=0.3', 'Accept':
> 'text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5',
> 'User-Agent': 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv: 1.8.0.8)
> Gecko/20061030 SeaMonkey/1.0.6', 'Host': 'localhost'}, referer:
> http://localhost/
> ...(multiple times)...
>
> Which is right i think... But my backend server gets this request:
>
> GET
> /VirtualHostBase/http/localhost:80/Editorial/VirtualHostRoot/
> HTTP/1.1
> Host: localhost:8081
> User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.8)
> Gecko/20061030 SeaMonkey/1.0.6
> Accept:
> text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5
> Accept-Language: el,en-us;q=0.7,en;q=0.3
> Accept-Encoding: gzip,deflate
> Accept-Charset: ISO-8859-7,utf-8;q= 0.7,*;q=0.7
> Referer: http://localhost/
> Cookie: wstyle=; __ac="YWRtaW46bWF0cml4";
> tree-s="eJzT0MgpMOQKVneEAKcAN19bda4CI67EkgJjLj0AegYHmA"
> Max-Forwards: 10
> X-Forwarded-For: 127.0.0.1
> X-Forwarded-Host: localhost
> X-Forwarded-Server: luna
>
> Thank you in advance,
>
> Ioannis Stavrinos
>
> _______________________________________________
> Mod_python mailing list
> Mod_python at modpython.org
> http://mailman.modpython.org/mailman/listinfo/mod_python
>
>


More information about the Mod_python mailing list