[mod_python] Proxy + Tomcat filter problems

Radosław Rymaszewski rrymaszewski at contentforces.pl
Thu Apr 17 11:02:20 EDT 2008


2008/4/17 Graham Dumpleton <graham.dumpleton at gmail.com>:

> 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.


thank You for your reply.

Tomcat content is buffered as You see below.

Could You explain in which place in code below headers are send to client  ?
I thought that in same time when script execute filter.write(), because
client always get header from last chunk

                try:
                    buffer = filter.req.buffer
                except AttributeError:
                    filter.req.buffer = Buffer()
                    buffer = filter.req.buffer

                s=filter.read()
                while s:
                    buffer.append(s)
                    s=filter.read()

                if s is None:
                    filter.req.headers_out['content-type'] = "text/html;
charset=UTF-8"
                    filter.req.headers_out['content-length'] =
str(len(buffer.string))
                    filter.req.content_type = "text/html; charset=UTF-8"
                    filter.req.set_content_length(len(buffer.string))
                    data = buffer.string
                else:
                    return
          filter.write(data)
          filter.close()

br
--
Radoslaw Rymaszewski
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mm_cfg_has_not_been_edited_to_set_host_domains/pipermail/mod_python/attachments/20080417/70a90e8d/attachment-0001.html


More information about the Mod_python mailing list