[mod_python] Re: Problem with mod_proxy + inputfilter + headers_in

Graham Dumpleton graham.dumpleton at gmail.com
Tue Apr 29 06:26:02 EDT 2008


2008/4/29 Emyr Thomas <emyr.thomas at gmail.com>:
> Thanks for the pointer to the docs Graham - those look very helpful.
>  I'll do my best to read them.
>
>  So in the case of tramline[1], the 'tramline' header which is being
>  set in the finalizeInput[2] method (which is called from a
>  PythonInputFilter) will never make it to the back end? This is indeed
>  the behaviour I am seeing.

If you have set things up to proxy the request after tramline has
capture the upload then probably no. If it was a mod_python handler
that was doing the read then it would be available after the read had
returned, but only to the mod_python handler.

>  What would be the correct way to set this
>  header?

Possibly not to use mod_python to implement it. I never understood why
tramline was even implemented in mod_python as mod_python input/output
filters aren't that efficient. You would be much better off doing it
as a special purpose C module for Apache, and most likely such a thing
does exist if one looked hard enough.

The only way one might do it with mod_python so that header is proxied
through, is to use a PythonFixupHandler to trigger the read of input
before the proxy handler is triggered in the response phase. That way
the header would exist and proxy handler may pass it through.

It has been a while since I looked at how tramline works, so this may
or may not work.

Graham

>  [1] http://codespeak.net/svn/rr/tramline/trunk/README.txt
>  [2] http://codespeak.net/svn/rr/tramline/trunk/src/tramline/core.py
>
>  Thank you so much for your help (and your patience!)
>
>  --Emyr
>
>
>
>  On Mon, Apr 28, 2008 at 10:09 PM, Graham Dumpleton
>  <graham.dumpleton at gmail.com> wrote:
>  > Sorry, one mistake I did make, was that you need earlier handler than
>  >  PythonFixupHandler if you want to affect access, authentication,
>  >  authorisation phases. Point is though that you can't do it in a
>  >  mod_python input filter as they only get triggered when content is
>  >  being read and after headers have been processed. There are input
>  >  filters that can process headers, but mod_python doesn't provide
>  >  access to writing them.
>  >
>  >  Graham
>  >
>  >  2008/4/29 Graham Dumpleton <graham.dumpleton at gmail.com>:
>  >
>  >
>  > > 2008/4/28 Emyr Thomas <emyr.thomas at gmail.com>:
>  >  >
>  >  > > Graham, out of interest, has this always been the case with mod_python, or
>  >  >  >  was this behavious introduced in a particular release?
>  >  >
>  >  >  This is nothing to do with mod_python, it is how underlying Apache C
>  >  >  APIs work. It has always been this way. If you have seen it behave any
>  >  >  other way, it would have been by luck due to calling sequences and not
>  >  >  guaranteed.
>  >  >
>  >  >  Suggest you dig through:
>  >  >
>  >  >   http://www.fmc-modeling.org/category/projects/apache/amp/Apache_Modeling_Project.html
>  >  >
>  >  >  to get a better understanding of how Apache works internally.
>  >  >
>  >  >  Graham
>  >  >
>  >  >
>  >  >
>  >  >  >  "Graham Dumpleton"
>  >  >  >  <graham.dumpleton at gmail.com> wrote in message
>  >  >  >  news:88e286470704191453o5b0b3c08u77b14064c1f58950 at mail.gmail.com...
>  >  >  >
>  >  >  >
>  >  >  > > 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
>  >  >  >  >>
>  >  >  >  >>
>  >  >  >
>  >  >  >
>  >  >  >
>  >  >  >  _______________________________________________
>  >  >  >  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