1CURLOPT_HTTPHEADER(3)               libcurl              CURLOPT_HTTPHEADER(3)
2
3
4

NAME

6       CURLOPT_HTTPHEADER - set of HTTP headers
7

SYNOPSIS

9       #include <curl/curl.h>
10
11       CURLcode curl_easy_setopt(CURL *handle, CURLOPT_HTTPHEADER,
12                                 struct curl_slist *headers);
13

DESCRIPTION

15       Pass  a  pointer to a linked list of HTTP headers to pass to the server
16       and/or proxy in your HTTP request. The same list can be used  for  both
17       host and proxy requests!
18
19       When  used  within  an  IMAP or SMTP request to upload a MIME mail, the
20       given header  list  establishes  the  document-level  MIME  headers  to
21       prepend to the uploaded document described by CURLOPT_MIMEPOST(3). This
22       does not affect raw mail uploads.
23
24       The linked list should be a  fully  valid  list  of  struct  curl_slist
25       structs properly filled in. Use curl_slist_append(3) to create the list
26       and curl_slist_free_all(3) to clean up an entire list.  If  you  add  a
27       header that is otherwise generated and used by libcurl internally, your
28       added one will be used instead. If you add a header with no content  as
29       in  'Accept:'  (no data on the right side of the colon), the internally
30       used header will get disabled. With this option you can add  new  head‐
31       ers,  replace  internal  headers  and remove internal headers. To add a
32       header with no content (nothing to the right side of  the  colon),  use
33       the form 'name;' (note the ending semicolon).
34
35       The  headers  included  in the linked list must not be CRLF-terminated,
36       because libcurl adds CRLF after each header  item.  Failure  to  comply
37       with  this  will  result  in  strange bugs because the server will most
38       likely ignore part of the headers you specified.
39
40       The first line in an HTTP request (containing the method, usually a GET
41       or POST) is not a header and cannot be replaced using this option. Only
42       the lines following the request-line are headers.  Adding  this  method
43       line  in  this  list of headers will only cause your request to send an
44       invalid header. Use CURLOPT_CUSTOMREQUEST(3) to change the method.
45
46       When this option is passed to  curl_easy_setopt(3),  libcurl  will  not
47       copy the entire list so you must keep it around until you no longer use
48       this handle for a transfer before you  call  curl_slist_free_all(3)  on
49       the list.
50
51       Pass a NULL to this option to reset back to no custom headers.
52
53       The most commonly replaced HTTP headers have "shortcuts" in the options
54       CURLOPT_COOKIE(3), CURLOPT_USERAGENT(3) and CURLOPT_REFERER(3). We rec‐
55       ommend using those.
56
57       There's  an  alternative  option that sets or replaces headers only for
58       requests that are sent with CONNECT to a proxy: CURLOPT_PROXYHEADER(3).
59       Use CURLOPT_HEADEROPT(3) to control the behavior.
60

SPECIFIC HTTP HEADERS

62       Setting some specific headers will cause libcurl to act differently.
63
64       Host:  The  specified host name will be used for cookie matching if the
65              cookie engine is also enabled for this transfer. If the  request
66              is done over HTTP/2 or HTTP/3, the custom host name will instead
67              be used in the ":authority" header field and Host: will  not  be
68              sent at all over the wire.
69
70       Transfer-Encoding: chunked
71              Tells libcurl the upload is to be done using this chunked encod‐
72              ing instead of providing the Content-Length: field  in  the  re‐
73              quest.
74

SPECIFIC MIME HEADERS

76       When  used to build a MIME e-mail for IMAP or SMTP, the following docu‐
77       ment-level headers can be set to override libcurl-generated values:
78
79       Mime-Version:
80              Tells the parser at the receiving site how to interpret the MIME
81              framing.   It  defaults  to "1.0" and should normally not be al‐
82              tered.
83
84       Content-Type:
85              Indicates the document's  global  structure  type.  By  default,
86              libcurl sets it to "multipart/mixed", describing a document made
87              of independent parts. When a MIME mail is only composed  of  al‐
88              ternative representations of the same data (i.e.: HTML and plain
89              text), this header must be set to  "multipart/alternative".   In
90              all cases the value must be of the form "multipart/*" to respect
91              the document structure and may not include the  "boundary="  pa‐
92              rameter.
93
94       Other specific headers that do not have a libcurl default value but are
95       strongly desired by mail delivery and user agents should  also  be  in‐
96       cluded.   These are "From:", "To:", "Date:" and "Subject:" among others
97       and their presence and value is generally checked by  anti-spam  utili‐
98       ties.
99

SECURITY CONCERNS

101       By  default,  this  option  makes libcurl send the given headers in all
102       HTTP requests done by this handle. You should therefore use this option
103       with  caution  if  you  for  example connect to the remote site using a
104       proxy and a CONNECT request, you should to consider if  that  proxy  is
105       supposed to also get the headers. They may be private or otherwise sen‐
106       sitive to leak.
107
108       Use CURLOPT_HEADEROPT(3) to make the headers only get sent to where you
109       intend them to get sent.
110
111       Custom headers are sent in all requests done by the easy handles, which
112       implies that if you tell libcurl to follow redirects (CURLOPT_FOLLOWLO‐
113       CATION(3)),  the  same set of custom headers will be sent in the subse‐
114       quent request. Redirects can of course go to other hosts and thus those
115       servers will get all the contents of your custom headers too.
116
117       Starting  in 7.58.0, libcurl will specifically prevent "Authorization:"
118       headers from being sent to other hosts than the first used one,  unless
119       specifically permitted with the CURLOPT_UNRESTRICTED_AUTH(3) option.
120
121       Starting in 7.64.0, libcurl will specifically prevent "Cookie:" headers
122       from being sent to other hosts than the first used one, unless specifi‐
123       cally permitted with the CURLOPT_UNRESTRICTED_AUTH(3) option.
124

DEFAULT

126       NULL
127

PROTOCOLS

129       HTTP, IMAP and SMTP
130

EXAMPLE

132       CURL *curl = curl_easy_init();
133
134       struct curl_slist *list = NULL;
135
136       if(curl) {
137         curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
138
139         list = curl_slist_append(list, "Shoesize: 10");
140         list = curl_slist_append(list, "Accept:");
141
142         curl_easy_setopt(curl, CURLOPT_HTTPHEADER, list);
143
144         curl_easy_perform(curl);
145
146         curl_slist_free_all(list); /* free the list */
147       }
148
149

AVAILABILITY

151       As long as HTTP is enabled. Use in MIME mail added in 7.56.0.
152

RETURN VALUE

154       Returns CURLE_OK if HTTP is supported, and CURLE_UNKNOWN_OPTION if not.
155

SEE ALSO

157       CURLOPT_CUSTOMREQUEST(3), CURLOPT_HEADEROPT(3), CURLOPT_PROXYHEADER(3),
158       CURLOPT_HEADER(3), CURLOPT_MIMEPOST(3), curl_mime_init(3)
159
160
161
162ibcurl 8.2.1                    April 26, 2023           CURLOPT_HTTPHEADER(3)
Impressum