[mod_python] sending headers directly to the client

Graham Dumpleton grahamd at dscpl.com.au
Sun May 14 21:56:03 EDT 2006


What you are wanting to do, detect client connection being closed
and aborting content generation, is generally seen as being bad
practice. Even if there were some way of doing it in the way you
are contemplating, you could run into problems with intermediate
proxies or firewalls stopping your scheme working because of
header buffering or other issues. You could also run into problems
with too much headers causing a client or intermediary to exceed
some size limit and simply aborting the whole request.

Why do you think what you want to do is a good idea? What
problem do you think you are trying to solve?

Graham

Stefan Wehr wrote ..
> Hi all,
> 
> I need to send headers directly to the client; that is, before
> mod_python sends its headers (I know that I have to handle the status
> line specially).
> 
> Background: I need to detect when the user hits the 'Cancel' button of
> the browser. The only reliable way to do this seems to send something
> periodically to the client. My idea is now to send dummy headers to
> the client until the possibly long running HTML code generating
> function is finished. Then I stop sending dummy headers and send the
> HTML code to the client. If the client hits 'Cancel' while the
> HTML code generating function is running, I'm able to detect this
> because I get some kind of error when sending a dummy header.
> 
> The problem is now: how can I send the dummy headers?
> 
> I cannot use 'req.write' because this flushes all headers (note that
> some headers can be set only *after* HTML has been generated).  My
> idea was then to use 'req.connection.write'. The problem with this
> approach is that this function does *not* trigger an error if the
> connection is closed. I also fiddled around with the
> 'req.connection.aborted' field without success.
> 
> Any help would be greatly appreciated.
> 
> Cheers, Stefan
> 
> _______________________________________________
> 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