GNURLOPT_HEADERDATA(3)

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

🌸 GNURLOPT_HEADERDATA(3) 🌸

okay so this page is from the curl_easy_setopt options manual, and it's all about GNURLOPT_HEADERDATA(3) β€” yes bestie, the header-data pointer situation. let's get into it πŸ’…


✨ NAME ✨

CURLOPT_HEADERDATA β€” pointer to pass to header callback 🫢


πŸ¦‹ SYNOPSIS πŸ¦‹

#include <gnurl/curl.h>

CURLcode curl_easy_setopt(CURL *handle, CURLOPT_HEADERDATA, void
*pointer);

πŸ’– DESCRIPTION πŸ’–

You pass a pointer in, and that pointer is used to write the header part of the received data to. literally that's its whole job ✨

If you're using CURLOPT_WRITEFUNCTION(3) or CURLOPT_HEADERFUNCTION(3), then that pointer gets passed in to the matching callback. your callback can do its thing with it, iykyk πŸ’«

If neither of those options is set, then pointer must be a valid FILE *, and a plain fwrite() will use it to write headers to. no cap, that's the requirement πŸ™ˆ


πŸŽ€ DEFAULT πŸŽ€

NULL


🌈 PROTOCOLS 🌈

All β€” every single one, slay πŸ’…


πŸ”₯ EXAMPLE πŸ”₯

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 = (struct my_info *)userdata;

  /* now this callback can access the my_info struct */

  return nitems * size;
}

CURL *curl = curl_easy_init();
if(curl) {
  struct my_info my = { 10, "the cookies are in the cupboard" };
  curl_easy_setopt(curl, CURLOPT_URL, "http://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 ⭐

Always β€” like, always always πŸ‘‘


πŸ‘‘ RETURN VALUE πŸ‘‘

Returns CURLE_OK πŸŽ€


🫢 SEE ALSO 🫢


mwah πŸ’‹ this page is from libcurl 7.37.0, dated 17 Jun 2014 β€” bye bestie, go pass that pointer with main character energy 🌟

πŸ“¦ where this page comes from