Streaming Response
# ################################################################################################ # I first posted this to zope@zope.org, without success. Although it is not about the development of # Zope itself, it deals with its internals, so now I post it here. # I hope everyone is alright with that. :-) # ################################################################################################ 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" 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. 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.) 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... I guess the answer lies somewhere in "Transfer-Encoding: chunked" but I can't figure out how to actually do it. :-) Maybe one of you guys working on HTTPResponse.py (Fred, Chris, Brian, Toby, Andreas) knows how to accomplish this? Anyone else? I appreciate the smallest hint. ;-) Thank you very much for your help, Danny P.S.: Please include my address in your reply ("Reply All") since I am currently not subscribed to this list. Thank you.
<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
At 05:58 PM 4/7/2003 -0700, Brett Carter wrote:
<snip>
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.
That would be really cool. I guess replacing will be fine: If I need to quote stuff from the "old" page, I'll just include it again...
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.
Mmmhhh. When playing around with "content-type" and "transfer-encoding" I actually got something back from IE6 that looked like it was doing the right thing. But then again there were "etag" and "transfer-ecnoding" quoted on the page, which I never (directly) invoked. Also some numbers. Very odd. I think I need a bit more insight on HTTPResponse.py and how it deals with manipulations, but I find it hard to read its source code. Also, what's the exact difference between streaming and chunking? (I've got an idea but no facts, esp. in regards to HTTPResponse.py)
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
Yup, read that. And I enjoyed reading "mimetools.choose_boundary()", too. lol My problem now is that I need something that works with IE. There's funny things going on with my hairs and toes when I hear the word "ActiveX plugin", so I'm still hoping for alternatives. Thank you for your response :-), and that library of yours sounds like a good thing(tm). Maybe you can ask your employer if you can pass it on. Cheers, Danny
-Brett
At 05:58 PM 4/7/2003 -0700, Brett Carter wrote:
<snip>
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.
What happens if Content-Length isn't set or set to an incorrect number (for instance larger that the expected result)? What does the standard say and how do browsers actually behave? Best Regards, Johan Carlsson -- Easy Publisher Developers Team Johan Carlsson johanc@easypublisher.com Mail: Birkagatan 9 SE-113 36 Stockholm Sweden Phone +46-(0)8-31 24 94 Fax +46-(0)8-675 04 44 Mobil +46-(0)70-558 25 24 http://www.easypublisher.com
Mmmhhh. When playing around with "content-type" and "transfer-encoding" I actually got something back from IE6 that looked like it was doing the right thing. But then again there were "etag" and "transfer-ecnoding" quoted on the page, which I never (directly) invoked. Also some numbers. Very odd.
I think I need a bit more insight on HTTPResponse.py and how it deals with manipulations, but I find it hard to read its source code. Also, what's the exact difference between streaming and chunking? (I've got an idea but no facts, esp. in regards to HTTPResponse.py)
I think you're confused - you don't need to look any further than the tools zope provides you - the setHeader and write methods off the RESPONSE object are all you need. HTTP push is a browser implemented protocol, all the server does is set a header and then iteratively send specially formatted chunks of data over HTTP.
My problem now is that I need something that works with IE. There's funny things going on with my hairs and toes when I hear the word "ActiveX plugin", so I'm still hoping for alternatives.
This doesn't work with IE5 or IE6 on the PC. It does work with IE5 on mac though strangely enough. One solution is not to use IE :)
Thank you for your response :-), and that library of yours sounds like a good thing(tm). Maybe you can ask your employer if you can pass it on.
Shure, I'll ask, but don't get your hopes up. In any case, it's a really simple library anyways. -Brett
At 11:36 2003-04-10 -0700, Brett Carter said:
My problem now is that I need something that works with IE. There's funny things going on with my hairs and toes when I hear the word "ActiveX plugin", so I'm still hoping for alternatives.
This doesn't work with IE5 or IE6 on the PC. It does work with IE5 on mac though strangely enough. One solution is not to use IE :)
What doesn't work in IE? Am I missing something? I tried the Python Script bellow with the same behavior in both IE (IE6) and Mozilla (each paragraph was written in intervals I don't now how to do a sleep in Python Scripts so I use a for loop that I trimmed to produce measurable intervals on my server (a rather slow machine)). Best Regards, Johan Carlsson RESPONSE = container.REQUEST.RESPONSE base =["<p>%s: Small 1</p>","<p>%s: Small 2</p>","<p>%s: Small 3</p>"] start="<html><head><title>It's comming: %s</title></head><body>" stop="<h1>%s</h1></body></html>" RESPONSE.setHeader('Content-Type', 'text/html') RESPONSE.write(start%"Starting") for i in range(800000): j=str(i) RESPONSE.write(base[0]%str(0)) for k in range(800000): j=str(k) RESPONSE.write(base[1]%str(1)) for t in range(800000): j=str(t) RESPONSE.write(base[2]%str(2)) for r in range(800000): j=str(r) RESPONSE.write(stop%'stop') -- Easy Publisher Developers Team Johan Carlsson johanc@easypublisher.com Mail: Birkagatan 9 SE-113 36 Stockholm Sweden Phone +46-(0)8-31 24 94 Fax +46-(0)8-673 04 44 Mobil +46-(0)70-558 25 24 http://www.easypublisher.com
On Tuesday 08 April 2003 1:20 am, Danny W. Adair wrote:
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.
How do I do this in Zope?
Just use RESPONSE.write and ZServer will take care of the rest automatically. -- Toby Dickenson http://www.geminidataloggers.com/people/tdickenson
At 08:20 AM 4/8/2003 +0100, Toby Dickenson wrote:
On Tuesday 08 April 2003 1:20 am, Danny W. Adair wrote:
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.
How do I do this in Zope?
Just use RESPONSE.write and ZServer will take care of the rest automatically.
Wow. (That's all for now...) Thanks, Danny
participants (5)
-
Brett Carter -
Brett Carter -
Danny W. Adair -
Johan Carlsson [EasyPublisher] -
Toby Dickenson