curl_mime_headers(3)

πŸ’… curl_mime_headers(3) β€” bestie's guide to mime part custom headers

okay so this is a page from the Library Functions Manual (libcurl girlies rise up ✨) and it's about giving a mime part its very own custom headers. yes. we're doing that. let's go 🫢


✨ NAME ✨

curl_mime_headers β€” set a mime part's custom headers πŸ’Œ


🌸 SYNOPSIS 🌸

#include <curl/curl.h>

CURLcode curl_mime_headers(curl_mimepart *part,
                           struct curl_slist *headers, int take_ownership);

πŸŽ€ DESCRIPTION πŸŽ€

curl_mime_headers(3) sets a mime part's custom headers. that's the whole vibe. it's giving "here's a little list of headers, please attach them to this part" πŸ‘‘

part β€” the part's handle, aka the spot where you're assigning the custom headers list to. main character part energy πŸ’…

headers β€” the head of a list of custom headers. and listen: it may be set to NULL to remove a previously attached custom header list. so NULL = yeet the old headers, no notes 🌈

take_ownership β€” when non-zero, it causes the list to be freed upon replacement or mime structure deletion. in this case the list must not be freed explicitly. like, hands off, she owns it now πŸ™ˆ

⚠️ real talk: if take_ownership is non-zero, do NOT free that list yourself. double-free is not the slay you think it is πŸ’€

setting a part's custom headers list multiple times is valid: only the value set by the last call is retained. last one wins, periodt ⭐


πŸ¦‹ PROTOCOLS πŸ¦‹

this functionality affects http, imap and smtp πŸ”₯


🧚 EXAMPLE 🧚

int main(void)
{
  struct curl_slist *headers = NULL;
  CURL *easy = curl_easy_init();
  curl_mime *mime;
  curl_mimepart *part;

  headers = curl_slist_append(headers, "Custom-Header: mooo");

  mime = curl_mime_init(easy);
  part = curl_mime_addpart(mime);

  /* use these headers in the part, takes ownership */
  curl_mime_headers(part, headers, 1);

  /* pass on this data */
  curl_mime_data(part, "12345679", CURL_ZERO_TERMINATED);

  /* set name */
  curl_mime_name(part, "numbers");

  /* Post and send it. */
  curl_easy_setopt(easy, CURLOPT_MIMEPOST, mime);
  curl_easy_setopt(easy, CURLOPT_URL, "https://example.com");
  curl_easy_perform(easy);
}

look at her go 😭🫢 she appended a header, made a part, handed the headers over with take_ownership = 1 (so no manual freeing, bestie), stuffed in the data, named the part "numbers", and posted it to https://example.com. iconic behaviour, no cap ✨


πŸ’œ AVAILABILITY πŸ’œ

added in curl 7.56.0 β€” so if you're on something ancient, it's giving retro, and this function is not gonna be there πŸ•°οΈ


πŸ‘‘ RETURN VALUE πŸ‘‘

this function returns a CURLcode indicating success or error. classic.

  • CURLE_OK (0) means everything was OK 😌
  • non-zero means an error occurred β€” see libcurl-errors(3) for the full tea πŸ’€

and if CURLOPT_ERRORBUFFER(3) was set with curl_easy_setopt(3), there can be an error message stored in the error buffer when non-zero is returned. so you get a little note explaining what went wrong, which lowkey slaps πŸ”


🌈 SEE ALSO 🌈


mwah πŸ’– that's the page! brought to you by libcurl, dated 2026-10-12 β€” go forth and attach those headers, bestie, you're gonna slay πŸŽ€βœ¨πŸ¦‹

πŸ“¦ where this page comes from