[mod_python] Proxy + Tomcat filter problems

Graham Dumpleton graham.dumpleton at gmail.com
Thu Apr 17 08:16:09 EDT 2008


2008/4/17 Radosław Rymaszewski <rrymaszewski at contentforces.pl>:
> Hello
>
> I was trying to find out solution for my problem but there were no answers,
> so I decided to write here.
>
> We are using mod_python filters for our system
>
> Infrastructure description:
>
> INTERNET <---> APACHE 2.8.3 with mod_python 3.3.1 + output filters <-->
> Apache proxy module <--> TOMCAT 5.5.2x
>
> our filters concat chunked content from tomcat and write to client whole
> changed content. It's important for us to get whole response from tomcat and
> after it process.
>
> problem is when filter.read() reach last byte (filter.read() == None) then
> there is no possibility to overwrite request headers.
>
> There is no such problem during reading content and when we serve static
> pages from apache www server.
>
> mod_python receive such headers
>
> 1 chunk
>
> [Wed Apr 16 05:52:15 2008] [error] {'Via': '1.1 domain', 'Set-Cookie':
> 'JSESSIONID=sessionXXX; Path=/path', 'Date': 'Fri, 18 Apr 2008 19:47:06
> GMT', 'Cache-Control': 'no-store', 'Cache-Control': 'no-cache', 'Expires':
> 'Thu, 01 Jan 1970 00:00:00 GMT', 'Pragma': 'No-cache', 'Server':
> 'Apache-Coyote'}
>
> 2 chunk
>
> [Wed Apr 16 05:52:15 2008] [error] {'Content-Type': 'text/plain',
> 'Transfer-Encoding': 'chunked', 'Connection': 'Keep-Alive', 'Keep-Alive':
> 'timeout=15, max=100', 'Via': '1.1 domain', 'Set-Cookie':
> 'JSESSIONID=sessionXXX; Path=/path', 'Cache-Control': 'No-cache', 'Expires':
> '0', 'Pragma': 'No-cache'}
>
> 3 chunk
>
>  [Wed Apr 16 05:52:15 2008] [error] {'Content-Type': 'text/plain',
> 'Transfer-Encoding': 'chunked', 'Connection': 'Keep-Alive', 'Keep-Alive':
> 'timeout=15, max=100', 'Via': '1.1 domain', 'Set-Cookie':
> 'JSESSIONID=sessionXXX; Path=/path', 'Cache-Control': 'No-cache', 'Expires':
> '0', 'Pragma': 'No-cache'}
>
> when I finish process on first or second chunk I can modify headers without
> any problems. after third one there is no such possibility
>
> Do You know what could be wrong ?

As soon as any filter following yours has caused any chunk of data to
be written back to client, it is too late to change headers. This is
because headers are sent before the data.

Thus, headers can only be reliably changed upon reading first chunk
and before it is written to next filter. Only other choice is to
buffer the whole content in your filter, fixup any headers based on
that content and then write the whole content.

Graham



More information about the Mod_python mailing list