Graham Dumpleton
graham.dumpleton at gmail.com
Thu Apr 17 19:32:16 EDT 2008
To be honest, I didn't think that headers could be modified in a mod_python output filter. This is because they are a resource type output filter and as such I understood they are not the type of output filter that gets called in the correct place to allow headers to be called. The filter type which probably allows modifying of headers is a protocol filter, but you can't create them with mod_python. Thus, if you are seeing headers modified at all is probably by luck and would be random. Since you said you were seeing changes, I had assumed that maybe my understanding that one couldn't change response headers in a mod_python output filter was wrong and thus why I suggested what I did because if anything would work, that would. My guess then is that you may be out of luck. Graham 2008/4/18 Radosław Rymaszewski <rrymaszewski at contentforces.pl>: > > > > 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 > > > > _______________________________________________ > Mod_python mailing list > Mod_python at modpython.org > http://mailman.modpython.org/mailman/listinfo/mod_python > >
|