views:

248

answers:

1

I'm reading this article about Comet http://en.wikipedia.org/wiki/Comet_(programming). It mentions that browser should support multipart/x-mixed-replace to make XmlHttpRequest Streaming possible.

Why this multipart/x-mixed-replace is necessary?

Without this header, HTTP response can still be chunked and sent piece by piece to browser, right?

+1  A: 

Make sense to you?

http://en.wikipedia.org/wiki/MIME#Mixed-Replace_.28Experimental.29

The content type multipart/x-mixed-replace was developed as part of a technology to emulate server push and streaming over HTTP. All parts of a mixed-replace message have the same semantic meaning. However, each part invalidates - "replaces" - the previous parts as soon as it is received completely. Clients should process the individual parts as soon as they arrive and should not wait for the whole message to finish.

schrodinger's code
But, without this header, the client can still get chunks of data, even each piece is not intended to "replace" former one. And the client can evaluate each piece without this header.
Morgan Cheng
have you tested that all of the clients can get the chunks of data without declaring this content type?
schrodinger's code
I tried it and find why. The onreadystatechange handler of XHR should check status and ready state. Without multipart, the handler will not get status==200 and readystate==4. As a result, the handler cannot respond in chunk.
Morgan Cheng
good to know it, well done!
schrodinger's code