CURLOPT_HEADER(3)

πŸ’… CURLOPT_HEADER(3) β€” the curl library manual, bestie edition πŸŽ€

So like, this is the libcurl manpage for CURLOPT_HEADER and we're gonna get into it ✨


🌸 NAME 🌸

CURLOPT_HEADER β€” pass headers to the data stream 🫢


✨ SYNOPSIS ✨

#include <curl/curl.h>

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

πŸ¦‹ DESCRIPTION πŸ¦‹

Okay so here's the vibe: you pass the long value onoff set to 1 and that's you asking libcurl to include the headers in the write callback (CURLOPT_WRITEFUNCTION(3)). Iconic. This option is actually relevant for protocols that genuinely have headers or other meta-data, like HTTP and FTP πŸ’–

Now, real talk: when you ask for the headers to get passed to the same callback as the body, it is not possible to accurately separate them again unless you have detailed knowledge about the protocol in use. So like, good luck separating your snack from your meal, iykyk 😭

Further β€” and this is the part people sleep on β€” the CURLOPT_WRITEFUNCTION(3) callback is limited to only ever getting a maximum of CURL_MAX_WRITE_SIZE bytes passed to it (16KB), while a header can be longer than that. Meanwhile CURLOPT_HEADERFUNCTION(3) supports getting called with headers up to CURL_MAX_HTTP_HEADER bytes big (100KB) πŸ”₯

So honestly? It is often better to use CURLOPT_HEADERFUNCTION(3) to get the header data separately. Just saying πŸ‘‘

Also a little warning bestie: while named confusingly similar, CURLOPT_HTTPHEADER(3) is the one used to set custom HTTP headers. Totally different thing. Don't get it twisted πŸ’€

πŸ“ DEFAULT πŸ“

0


🧚 PROTOCOLS 🧚

This functionality affects ftp, http, imap, pop3 and smtp 🌈


πŸ’œ EXAMPLE πŸ’œ

int main(void)
{
  CURL *curl = curl_easy_init();
  if(curl) {
    curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");

    curl_easy_setopt(curl, CURLOPT_HEADER, 1L);

    curl_easy_perform(curl);
  }
}

⭐ AVAILABILITY ⭐

Added in curl 7.1 🫢


πŸ’… RETURN VALUE πŸ’…

curl_easy_setopt(3) returns a CURLcode indicating success or error.

CURLE_OK (0) means everything was OK β€” slay. Anything non-zero means an error occurred, so go check libcurl-errors(3) πŸ”


🌸 SEE ALSO 🌸


okay that's the whole page, mwah πŸ’‹ this was the libcurl manual page, dated 2026-10-12, and yeah β€” the manual name is CURLOPT_HEADER(3), in case you forgot already πŸ™ˆ go forth and header responsibly bestie πŸ’–βœ¨

πŸ“¦ where this page comes from