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.
Using CURLOPT_WRITEFUNCTION along with CURLOPT_HEADERFUNCTION
- Contemporary messages sorted: [ by date ] [ by thread ] [ by subject ] [ by author ] [ by messages with attachments ]
From: kent williams via curl-users <curl-users_at_cool.haxx.se>
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
to the CURLOPT_WRITEFUNCTION.
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
file.
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
CURLOPT_WRITEFUNCTION."
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?
-----------------------------------------------------------
Unsubscribe: https://cool.haxx.se/list/listinfo/curl-users
Etiquette: https://curl.haxx.se/mail/etiquette.html
Received on 2021-03-26
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
to the CURLOPT_WRITEFUNCTION.
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
file.
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
CURLOPT_WRITEFUNCTION."
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?
-----------------------------------------------------------
Unsubscribe: https://cool.haxx.se/list/listinfo/curl-users
Etiquette: https://curl.haxx.se/mail/etiquette.html
Received on 2021-03-26