CURLOPT_HEADERDATA(3)
π NAME π
okay so this is the CURLOPT_HEADERDATA(3) page from the Library Functions Manual, and it's literally about a pointer you pass to your header callback. No cap.
CURLOPT_HEADERDATAβ pointer to pass to header callback
β¨ SYNOPSIS β¨
#include <curl/curl.h>
CURLcode curl_easy_setopt(CURL *handle, CURLOPT_HEADERDATA, void *pointer);
π¦ DESCRIPTION π¦
Bestie, you pass a pointer in here, and that pointer is used to write the header part of the received data to. It's giving "custom data delivery service" β¨.
If CURLOPT_WRITEFUNCTION(3) or CURLOPT_HEADERFUNCTION(3) is used, pointer is passed in to the respective callback. So your callback can be like "oh hey, this is my stuff" π
.
If neither of those options are set, pointer must be a valid FILE * and it is used by a plain fwrite() to write headers to. Literally must be valid β no playing around.
π¨ warning, bestie: if you are using libcurl as a Windows DLL, you must useCURLOPT_WRITEFUNCTION(3)orCURLOPT_HEADERFUNCTION(3)if you set this option or you might experience crashes. Not cute. Not slay. Use the callback.
π DEFAULT π
NULL β iconic empty-handed start.
π PROTOCOLS π
This functionality affects all supported protocols. Every single one, periodt.
π EXAMPLE π
Here's the code. Copy it exactly, don't freestyle the literals:
struct my_info {
int shoesize;
char *secret;
};
static size_t header_callback(char *buffer, size_t size,
size_t nitems, void *userdata)
{
struct my_info *i = userdata;
printf("shoe size: %d\n", i->shoesize);
/* now this callback can access the my_info struct */
return nitems * size;
}
int main(void)
{
CURL *curl = curl_easy_init();
if(curl) {
struct my_info my = { 10, "the cookies are in the cupboard" };
curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
curl_easy_setopt(curl, CURLOPT_HEADERFUNCTION, header_callback);
/* pass in custom data to the callback */
curl_easy_setopt(curl, CURLOPT_HEADERDATA, &my);
curl_easy_perform(curl);
}
}
π AVAILABILITY π
Added in curl 7.10. Old-school but still iconic.
π RETURN VALUE π
curl_easy_setopt(3) returns a CURLcode indicating success or error.
CURLE_OK (0) means everything was OK. Non-zero means an error occurred β see libcurl-errors(3). Fr fr.
π₯ SEE ALSO π₯
mwah π this page's footer tea is: source/version libcurl, date 2026-10-12. Stay hydrated and validate your FILE *, bestie π«Ά
π¦ where this page comes from
- fedora 44: libcurl-devel 8.18.0-14.fc44 Β· curl
- fedora 44: libcurl-devel 8.18.0-14.fc44 Β· curl
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms