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.
Multipart requests combine one or more sets of data into a single body, separated by boundaries. You typically use these requests for file uploads and for transferring data of several types in a single request (for example, a file along with a JSON object).
8 1 Interesting answer. In my case, I wanted multipart to reduce requests and improve browser loading time. If done in js though, parsing it manually would increase the time and probably makes no sense to compensate the roundtrip.
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.
You add encoding as a child of the media type property, one the same level where schema is located. In the example below, we set the contentType for the profileImage part of a multipart request to image/png, image/jpg: Parts of multipart requests usually do not use any headers, except for Content.
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:
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"> </head> <body> Hello from a html <script type="text/javascript" src="http://localhost:2080/file.js"></script> </body> </html> --sample_boundary--
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With