Hotspots: Admin Pages | Turn-in Site |
Current Links: Cases Final Project Summer 2007
Multipart Responses in HTTP
HTTP responds with a MIME document. MIME documents have a "content type", which is normally something like text/plain or image/gif or audio/mpeg. However, it can also be multipart/x-mixed-replaced, a document type that includes a sequence of documents within itself. Many new browsers support this experimental MIME type.
When a supporting browser sees a response of type multipart/x-mixed-replaced, it will display the parts of the response one after another. Furthermore, (BIG HINT!) most modern browsers will display early parts of the response even though later parts have not yet finished downloading.
The format of a multipart/x-mixed-replaced document
The format is exactly the same as for any multipart MIME message. Here it is summarized, though you should go to the RFC's with any question.
First, you need to choose a boundary string and declare it in the header of the response. If your boundary string is "abracadabra", then the header looks like this:
Content-type: multipart/x-mixed-replace; boundary="abracadabra"
Second, you need to send the content parts. Each part should be preceded by '–' and your boundary, on its own line. For example, if your boundary is 'abracadabra', then you need to precede each part with '–abracadabra' on its own line. The last part should be followed by the same string parts are preceded by, only with '–' added to the end as well. For the 'abracadabra' example, you would follow the last part with '–abracadabra–'.
Finally, don't forget that the document parts are themselevs in mail format. Thus they need headers the same way the entire response does. Usually, you will need two headers, Content-Type and (preferably) Content-Length.
Here is an example of an entire multipart document, suitable for returning from HTTP:
Content-type: multipart/x-mixed-replace; boundary="abracadabra"--abracadabraContent-type: text/html<h1>This is the first page...</h1>--abracadabraContent-type: text/plain
And this is the last.
!!!Where does this work?Lex has set up a test server at: http://stingray.cc.gatech.edu:8888/testmulti. People are encouraged to list below any successes or failures they find....!Success reports:-Netscape 4.76 on Linux/x86-Netscape 4.76 on Windows 98/NT/2000 (muhahah)
- Netscape 4.07 on Windows 98
- Netscape 6, Windows 2000 (sort of, needs further testing)
- Netscape 4.76 on MacOS 9
- Internet Explorer, WinNT 5.00.2919.6307
- Internet Explorer 5.5, Windows 2000
- Opera 5.0b6 on Linux/x86
- Lynx 2.8.3rel.1.1 on Linux/x86 (and probably anywhere)
- W3 (WWW 4.0pre.46, URL p4.0pre.46, MM 1.96) on Linux/x86 (and probably anywhere)
Someone should really dig up some relevant RFC's and tutorials, but Lex thinks he's done enough. If you find something, though, you might want to list it here.
Netscape page on Server push\pull. Scroll down about halfway.
Intro to Server Push page - uses multipart/x-mixed-replace.
HTTP separates lines with CR-LF pairs, but Squeak uses lone CR's. So if you try to return a literal string with embedded newlines across an HTTP socket, it won't always work. Two ways to get CR-LF line endings are: use "String crlf", or send #withInternetLineEndings to a string with embedded CR's of any kind.
Link to this Page