* Daniel Stenberg <[email protected]> [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
http-server.sh
Description: Bourne shell script
#include <stdio.h>
#include <stdlib.h>
#include <err.h>
#include <curl/curl.h>
static size_t
on_curl_write_header(void *buf, size_t size, size_t nmemb, void *userp)
{
size_t len = size * nmemb;
printf("received %5zu bytes\n", len);
return (len);
}
int
main(int argc, char *argv[])
{
CURL *curl;
CURLcode retval;
curl = curl_easy_init();
if (curl == NULL) {
err(1, "curl_easy_init");
}
curl_easy_setopt(curl, CURLOPT_URL, "http://127.0.0.1:8000/");
curl_easy_setopt(curl, CURLOPT_HEADERFUNCTION, on_curl_write_header);
retval = curl_easy_perform(curl);
if (retval != CURLE_OK) {
warnx("curl_easy_perform: %s", curl_easy_strerror(retval));
goto out;
}
out:
curl_easy_cleanup(curl);
exit(0);
}
------------------------------------------------------------------- Unsubscribe: https://cool.haxx.se/list/listinfo/curl-library Etiquette: https://curl.haxx.se/mail/etiquette.html
