xref: /curl/docs/libcurl/curl_mime_headers.md (revision 5a488251)
1---
2c: Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
3SPDX-License-Identifier: curl
4Title: curl_mime_headers
5Section: 3
6Source: libcurl
7See-also:
8  - curl_mime_addpart (3)
9  - curl_mime_name (3)
10Protocol:
11  - HTTP
12  - IMAP
13  - SMTP
14Added-in: 7.56.0
15---
16
17# NAME
18
19curl_mime_headers - set a mime part's custom headers
20
21# SYNOPSIS
22
23~~~c
24#include <curl/curl.h>
25
26CURLcode curl_mime_headers(curl_mimepart *part,
27                           struct curl_slist *headers, int take_ownership);
28~~~
29
30# DESCRIPTION
31
32curl_mime_headers(3) sets a mime part's custom headers.
33
34*part* is the part's handle to assign the custom headers list to.
35
36*headers* is the head of a list of custom headers; it may be set to NULL
37to remove a previously attached custom header list.
38
39*take_ownership*: when non-zero, causes the list to be freed upon
40replacement or mime structure deletion; in this case the list must not be
41freed explicitly.
42
43Setting a part's custom headers list multiple times is valid: only the value
44set by the last call is retained.
45
46# %PROTOCOLS%
47
48# EXAMPLE
49
50~~~c
51int main(void)
52{
53  struct curl_slist *headers = NULL;
54  CURL *easy = curl_easy_init();
55  curl_mime *mime;
56  curl_mimepart *part;
57
58  headers = curl_slist_append(headers, "Custom-Header: mooo");
59
60  mime = curl_mime_init(easy);
61  part = curl_mime_addpart(mime);
62
63  /* use these headers in the part, takes ownership */
64  curl_mime_headers(part, headers, 1);
65
66  /* pass on this data */
67  curl_mime_data(part, "12345679", CURL_ZERO_TERMINATED);
68
69  /* set name */
70  curl_mime_name(part, "numbers");
71
72  /* Post and send it. */
73  curl_easy_setopt(easy, CURLOPT_MIMEPOST, mime);
74  curl_easy_setopt(easy, CURLOPT_URL, "https://example.com");
75  curl_easy_perform(easy);
76}
77~~~
78
79# %AVAILABILITY%
80
81# RETURN VALUE
82
83CURLE_OK or a CURL error code upon failure.
84