curl-library
Re: Incorrect documentation of CURLOPT_HEADERFUNCTION
Date: Thu, 15 Feb 2018 23:39:05 +0100
* Daniel Stenberg <daniel_at_haxx.se> [2018-02-15 22:10]:
> On Thu, 15 Feb 2018, Guido Berhoerster wrote:
>
>>> The header callback will be called once for each header and only
>>> complete header lines are passed on to the callback. Parsing headers
>>> is very easy using this.
>>
>> This seems to be completely wrong, headers are chopped into chunks of
>> CURL_MAX_WRITE_SIZE by Curl_client_chop_write(). The only way to distinguish
>> a complete header seems to be a check whether the last character is a 0x0a.
>
> The documentation is right here, the code is wrong. The code is supposed to
> always deliver a full header or none at all. This is a bug.
OK
>> This also doesn't seem to be true, with libcurl 7.55.1 headers up to ~ 190K
>> are read although I haven't checked where that limit actually comes from.
>
> Please let me know how to reproduce that, I can't. I just wrote up a test case
> with a header line that is longer than 102400 bytes and it ends up with:
>
> curl: (27) Avoided giant realloc for header (max is 102400)!
That happens with the curl tool, but using the attached test case it'll read
headers for up to 191K and pass them to the header function in 16K chunks:
$ ./http-server.sh &
[1] 14366
$ ./header-write-test
GET / HTTP/1.1
Host: 127.0.0.1:8000
Accept: */*
received 17 bytes
received 16384 bytes
received 16384 bytes
received 16384 bytes
received 16384 bytes
received 16384 bytes
received 16384 bytes
received 16384 bytes
received 16384 bytes
received 16384 bytes
received 16384 bytes
received 16384 bytes
received 15362 bytes
received 19 bytes
received 2 bytes
-- Guido Berhoerster
-------------------------------------------------------------------
Unsubscribe: https://cool.haxx.se/list/listinfo/curl-library
Etiquette: https://curl.haxx.se/mail/etiquette.html
- application/x-sh attachment: http-server.sh
- text/x-csrc attachment: header-write-test.c