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
- 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