cURL / Mailing Lists / curl-library / Single Mail


Re: how libcurl receives chunked data from http server?

From: Daniel Stenberg <>
Date: Mon, 22 Sep 2003 01:34:32 +0200 (CEST)

On Sat, 20 Sep 2003, Jerry G. Chiuan wrote:

> My http server responds to the client a huge data that can't be carried by
> single TCP segment. the data size = 1160 + 1460*6 + 337 = 10,257 (bytes),
> please refer to info. shown below
> As a result, it needs totally 8 TCP segments to transfer, the first one
> carries http header.
> My question is:
> - can libcurl handle this kind of response?

Are you seriously believing that all the applications that use libcurl,
including the curl tool, all are limited to transfers less than 10K ?

libcurl supports sizes up to at least 2GB, and more than so if the server
sends the data chunked.

> Its header has the field called "Transfer-Encoding: chunked", meanwhile it
> has "1ff8" between http header part and http data part in the first TCP
> segment.

libcurl supports and deals with chunked transfers. You should not even have to
know that it is sent chunked.

> I have no idea why it carries "1ff8" between http header and http data. is
> it for encoding?

That's what the chunked encoding means. It basicly sends a series of blocks
using a format like "[hexadecimal size][data]", ending with one block that has
the size set to zero.

> supposely the http header shall ends with "...."

A HTTP header ends with an empty line ending with CRLF.

> then followed by data part directly, right?


> - If yes, can libcurl receive all binary data at a time in libcurl's buffer?

libcurl will receive N bytes into its buffer and then call the write callback.
You shall not assume any size, as libcurl is not guaranteed to get or use any
specific size. It of course has an internal buffer of a certain size so you
can be sure to never get any MORE data than CURL_MAX_WRITE_SIZE bytes in one
single function call.

> I found that CURLOPT_WRITEFUNCTION would be called several times in order to
> receive the whole data.

Yes of course.

> For instance, it might receive first 2 packets, then receive the rest etc...
> how can we receive the data at a time with libcurl? can it be configured?

You can't. Unless you patch libcurl to do so. I just don't see the point in
adding such an option. You would add significant complexity to the code

 Daniel Stenberg -- curl: been grokking URLs since 1998
This email is sponsored by:ThinkGeek
Welcome to geek heaven.
Received on 2003-09-22