[Zope-dev] Streaming Response
Brett Carter
brett-zopedev@kavi.com
Mon, 7 Apr 2003 17:58:17 -0700
<snip>
> Hi,
>
> I would like to show status messages while calling a couple of functions
> from within a Python Script: While the script is running, I want to
> successively output messages like
>
> ------------------------
> Doing this...ok
> Doing that...ok
> Done
> ------------------------
> and then either redirect or display a button to move on.
>
> 1. I do _not_ want to use JavaScript
> 2. I do _not_ want to use the meta tag "refresh"
Ok, there's more than one way to skin a cat...
> I would like to use Response.write() to push my status messages on the fly.
> Since I don't know which function calls will succeed and which will fail, I
> do not know "Content-Length" in advance. Therefore, I would like to use a
> streaming/chunked response as specified in HTTP 1.1.
I just finished a library to do just this. I'll have to ask my employer if
I can release it, but I'm not sure http chunking is exactly what you want.
Chunking takes the current page and dynamically replaces it with whatever
new content you send in each chunk.
> How do I do this in Zope?
>
> I tried to do "response.setHeader('Content-Type',
> 'multipart/x-mixed-replace')" but couldn't get it working. (Also, it looks
> as if this will only work in Netscape but not IE. True? Then unfortunately
> I can't go that route anyway.)
You're on the right track, I just used a combonation of response.setHeader
and response.write. You're also correct that IE doesn't support chunking;
better send a bug report to bill. That said, I'm not sure this method ever
even made it into the HTTP spec, but all netscape and gecko based browsers
support it in my experience. I've seen other sites make IE work with an
ActiveX plugin of some sort; don't ask me where or how to get it, I don't
do IE.
> I also tried to leave the header alone and just "Response.write()" the
> multipart content-type and its boundary and the content-type's of the
> parts, but ZPublisher just returned the plain text...
Getting the headers set correctly is a bit tricky, each chunk needs to be
delimited by a set of boundry strings defined when you first set your
content type header. The full explaination is at:
http://wp.netscape.com/assist/net_sites/pushpull.html
-Brett