cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: Multi-part server push

From: Gerald Dalley <dalleyg_at_mit.edu>
Date: Wed, 10 Nov 2004 07:59:15 -0500

Daniel Stenberg wrote:
> Gerald Dalley wrote:
>> I have a server that I'm connecting to that returns an infinite
stream of
>> data that includes timestamps, some text messages, and jpeg images.
> I suppose "infinite" was just a slight exaggeration?

Only a slight one actually. The web server is connected to a sensor
that can be configured to stream its readings to a client. By
"infinite", I mean that there is no fundamental finite limit to the
amount of data it can send, based on the protocol.

>> If I connect to the server using the easy interface, I get a header
of the
>> form: Content-Type: multipart/x-mixed-replace;boundary=--myboundary
Is there
>> a way to have cURL return the headers and the content of the multipart
>> returned data?
>
> You mean you want the MIME stream separated in some clever way? No,
libcurl
> won't do that. It will give you the HTTP headers and the HTTP body
separately,
> but you will have to split up the body as you see fit. libcurl has no
actual
> understanding of any data formats.

Okay, I think I'll write a custom parser for the multipart section for
now.

While I'm at it though, I'll go ahead and put in a feature request since
I imagine that I'm not the only one who needs to deal with multi-part
responses (you seem to have very good support for multi-part requests)...

The stream of data that I receive has the form (with line numbers added
for reference purposes):
-------cut here--------------
01: HTTP/1.1 200 OK\r\n
02: Content-Type: multipart/x-mixed-replace;boundary=--myboundary\r\n
03: --myboundary\r\n
04: Content-Type: <binary data type>\r\n
05: Time: 2003-01-06 Mon 21:00:05\r\n
06: \r\n
07: <binary data>\r\n
08: --myboundary\r\n
09: Content-Type: <binary data type>\r\n
10: Time: 2003-01-06 Mon 21:00:06\r\n
11: \r\n
12: <binary data>\r\n
13: --myboundary\r\n
14: Content-Type: <binary data type>\r\n
15: Time: 2003-01-06 Mon 21:00:07\r\n
16: ExtraHeader: Some extra data from the sensor\r\n
17: \r\n
18: <binary data>\r\n
19: --myboundary\r\n
...
----------end cut-------------

It would be really cool if cURL set up the following callbacks (or at
least something along these lines):
    header_function
       Does what the current header function does, e.g. traps line 2
       Some part of cURL also detects the multipart header and
          recognizes the boundary parameter
    subheader_function
       Does what header_function does, except it gets called when
          there are headers in the multipart section
       Traps lines 4, 5, 9, 10, 14, 15, 16
    write_function
       Instead of trapping lines 3-19 as one big chunk, it now
          only returns lines 7, 12, and 18

BTW, great library you have here! After going through the tutorial,
it's pretty easy to use.

--Gerald Dalley
  dalleyg_at_mit.edu
Received on 2004-11-10