curl / Mailing Lists / curl-users / Single Mail
Buy commercial curl support from WolfSSL. We help you work out your issues, debug your libcurl applications, use the API, port to new platforms, add new features and more. With a team lead by the curl founder himself.


From: kent williams via curl-users <>
Date: Fri, 26 Mar 2021 11:30:32 -0500

Fixing a bug in our application that uses libcurl:

Before I allowed saving request to a file (with CURLOPT_WRITEFUNCTION)
or capturing response headers (with CURLOPT_HEADERFUNCTION) but not both.

So, naturally, I get a request to allow both at once.  The catch is that
if you turn on CURLOPT_HEADER, the headers always go into the data sent

I have a solution but it feels kind of wonky. The CURLOPT_WRITEFUNCTION
buffers all the data it gets, and checks it for "\r\n\r\n"  Once it sees
that, it knows the headers are done, and writes the rest of the data to

It would be EASIER if the observed behavior could be depended on: i.e. 
the write function always gets a line at a time, at least while getting
the headers.  If that were the case I could check for a line that's just
"\r\n" and know headers were done.

I didn't find a CURLOPT that tells libcurl "don't send headers to the

I also didn't see any guarantee that the CURLOPT_WRITEFUNCTION can
depend on its data being null-terminated strings, a line at a time,
though that certainly is what I observed.

How do other people solve this issue?

Received on 2021-03-26