[mod_python] strange behaviour with compressed response

Graham Dumpleton grahamd at dscpl.com.au
Wed Jan 3 16:05:59 EST 2007


Jim Gallacher wrote ..
> m.banaouas wrote:
> > Hi,
> > 
> >  >req.sendfile('c:/apache/htdocs/myfile.xml')
> > In my real case, the response contain "dynamic" data built with database
> > extracted rows.
> > So it's may be not the best thing to do (storing it first in a file).
> > 
> >  >       SetOutputFilter DEFLATE
> > Now, it works finally! even without this directive.
> > 
> > In fact the right question would be:
> > "what is the difference between req.write(bla) and return bla ?"
> 
> Very little. When you return something using mod_python.publisher, it 
> still calls req.write() internally.
> 
> Perhaps the biggest difference is that mod_python.publisher calls 
> req.write with flush=0, whereas the default is flush=1.
> 
> This could have implications concerning the setting of the 
> Content-Length header versus use of Transfer-Encoding: chunked. (I'm not
> 100% sure about that, but I have the idea that by not immediately 
> flushing to the client Apache may be able to set the Content-Length header).

Correct. One can use:

  req.add_output_filter('CONTENT_LENGTH')

and provided all writes have flush=0, Apache will be able to set the
content length output header for you automatically.

Obviously, in doing this, all the content is buffered up within Apache
so doing it on very large files would not be a good idea.

The AddOutputFilter directive can also be used in the Apache
configuration to add this output filter to the processing chain.

Graham

> On the other hand, your client is using HTTP/1.0 which may introduce 
> other complications. (IIRC HTTP/1.0 does not support Transfer-Encoding)
> 
>   > Firefox browser is certainly http-tolerant and can manage some
> > "imperfect" http dialogs.
> > Of course, the problem I meet could be caused by bad implementation in
> > MyHttpClient side.
> > But the same comp in the sames conditions fails when response is 
> > "written" and works fine when the response is "returned", bizare non
> ?
> 
> I suspect it may be some implementation detail in your client.
> 
> Jim
> _______________________________________________
> 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