View this PageEdit this PageAttachments to this PageHistory of this PageHomeRecent ChangesSearch the SwikiHelp Guide
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: 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)

Failure reports:

Relevant Links

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/1.1 protocol.

Common Problems

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