views:

745

answers:

4

Hi, I would like to create a HTTP response, using multipart/mixed, but I'm not sure which browsers support it; and if it's as convenient as it sounds, from the client's point of view. To be honest, I do not need specifically that content type. I just want to transmit more than one file in the same response; maybe there's another content-type more used.

A: 

I can't find any good information on Google, so you'll have to test it

  • Build a simple page which is sent as multipart
  • Test in various browsers
  • Post results here :) (This page is the second result in Google when searching for this)
Bart van Heukelom
I'll try it soon. Thanks!
Diego Jancic
+2  A: 

I've tested it, with a home-made server and a simple response. Not sure if the response is well-formed because no browser understands it 100% OK. But here are the results:

  • Firefox 3.5: Renders only the last part, others are ignored.
  • IE 8: Shows all the content as if it were text/plain, including the boundaries.
  • Chrome 3: Saves all the content in a single file, nothing is rendered.
  • Safari 4: Saves all the content in a single file, nothing is rendered.
  • Opera 10.10: Something weird. Starts rendering the first part as plain/text, and then clears everything. The loading progress bar hangs on 31%.

Here's the complete response, if anyone finds any error, please tell me and I'll try again:

HTTP/1.1 200 OK
Date: Tue, 01 Dec 2009 23:27:30 GMT
Vary: Accept-Encoding,User-Agent
Content-Length: 681
Content-Type: Multipart/mixed; boundary="sample_boundary";

Multipart not supported :(
--sample_boundary
Content-Type: text/css; charset=utf-8
Content-Location: http://localhost:2080/file.css

body
{
 background-color: yellow;
}
--sample_boundary
Content-Type: application/x-javascript; charset=utf-8
Content-Location: http://localhost:2080/file.js

alert("Hello from a javascript!!!");

--sample_boundary
Content-Type: text/html; charset=utf-8
Content-Base: http://localhost:2080/

<html>
<head>
    <link rel="stylesheet" href="http://localhost:2080/file.css"&gt;
</head>
<body>
 Hello from a html
    <script type="text/javascript" src="http://localhost:2080/file.js"&gt;&lt;/script&gt;
</body>
</html>
--sample_boundary--
Diego Jancic
+1  A: 

In my experience, multipart responses work in Firefox but not in Internet Explorer. This was 2 years ago, using the browsers of the time.

I have had HTTP multipart responses working for a stream of JPEG images. For example, Axis IP cameras use for their motion JPEG stream for Firefox. For Internet explorer, Axis require the use of a plugin.

If Firefox-only support meets your requirements, then I recommend setting the content-length header in each part of the multi-part response. It might help to make the boundary string identical in the original HTTP header and the multi-part response (the '--' is missing in the HTTP header).

Thomas Bratt
A: 

Two ideas:

  1. Formatting: I think "multipart" should be in lower case, and I don't think a semicolon is expected at the end of the Content-type header (although it's doubtful that it will make a difference, it's possible that it might).
  2. Have you tried replace mode? Just use: Content-type: multipart/x-mixed-replace -- everything else should stay the same.
RickNZ
I'll try it soon. Thanks!
Diego Jancic