GNURLOPT_HEADER(3)

πŸ“¦ version 7.72.0, in nixos 26.05, nixpkgs unstable

πŸ’… GNURLOPT_HEADER(3) πŸ’…

okay so bestie, welcome to the curl_easy_setopt options corner of the manual β€” this one's all about CURLOPT_HEADER, and ngl it's a classic case of "the name does not mean what you think" 🫢


✨ NAME ✨

CURLOPT_HEADER β€” pass headers to the data stream


✨ SYNOPSIS ✨

#include <gnurl/curl.h>

CURLcode curl_easy_setopt(CURL *handle, CURLOPT_HEADER, long onoff);

✨ DESCRIPTION ✨

okay so here's the vibe 🌸 β€” you pass a long value called onoff, and if you set it to 1, you're literally asking libcurl to include the headers in the write callback (CURLOPT_WRITEFUNCTION(3)). icon behavior. this option is only relevant for protocols that actually have headers or other meta-data, like HTTP and FTP πŸ‘‘

but like… here's the thing. when you ask for the headers to go to the same callback as the body, it is not possible to accurately separate them again without detailed knowledge about the protocol in use. 😭 so like, you can do it, but you're kind of on your own after that.

further (and this part matters, fr fr): the CURLOPT_WRITEFUNCTION(3) callback is limited to only ever get a maximum of CURL_MAX_WRITE_SIZE bytes passed to it (16KB), while a header can be longer. meanwhile CURLOPT_HEADERFUNCTION(3) supports getting called with headers up to CURL_MAX_HTTP_HEADER bytes big (100KB). so like, different ceilings entirely πŸ’€

so the tea is: it is often better to use CURLOPT_HEADERFUNCTION(3) to get the header data separately. slay.

⚠️ and while it's named confusingly similar β€” CURLOPT_HTTPHEADER(3) is used to set custom HTTP headers! not this! don't get it twisted bestie πŸ™ˆ

✨ DEFAULT ✨

0


✨ PROTOCOLS ✨

Most 🌈


✨ EXAMPLE ✨

CURL *curl = curl_easy_init();
if(curl) {
  curl_easy_setopt(curl, CURLOPT_URL, "http://example.com");

  curl_easy_setopt(curl, CURLOPT_HEADER, 1L);

  curl_easy_perform(curl);
}

✨ RETURN VALUE ✨

Returns CURLE_OK. that's it, that's the whole vibe ✨


πŸ¦‹ SEE ALSO πŸ¦‹


πŸŽ€ and that's the page! this little beauty came to you from libcurl 7.37.0, dated 16 Jun 2014 β€” yes she's an elder icon and she still ate πŸ’œ bye bestie, go read the HEADERFUNCTION one next, iykyk 🧚

πŸ“¦ where this page comes from