CURLOPT_HTTPHEADER.3 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. .\" generated by cd2nroff 0.1 from CURLOPT_HTTPHEADER.md
  2. .TH CURLOPT_HTTPHEADER 3 "2025-01-17" libcurl
  3. .SH NAME
  4. CURLOPT_HTTPHEADER \- set of HTTP headers
  5. .SH SYNOPSIS
  6. .nf
  7. #include <curl/curl.h>
  8. CURLcode curl_easy_setopt(CURL *handle, CURLOPT_HTTPHEADER,
  9. struct curl_slist *headers);
  10. .fi
  11. .SH DESCRIPTION
  12. Pass a pointer to a linked list of HTTP headers to pass to the server and/or
  13. proxy in your HTTP request. The same list can be used for both host and proxy
  14. requests!
  15. When used within an IMAP or SMTP request to upload a MIME mail, the given
  16. header list establishes the document\-level MIME headers to prepend to the
  17. uploaded document described by \fICURLOPT_MIMEPOST(3)\fP. This does not affect
  18. raw mail uploads.
  19. The linked list should be a fully valid list of \fBstruct curl_slist\fP
  20. structs properly filled in. Use \fIcurl_slist_append(3)\fP to create the list
  21. and \fIcurl_slist_free_all(3)\fP to clean up an entire list. If you add a
  22. header that is otherwise generated and used by libcurl internally, your added
  23. header is used instead. If you add a header with no content as in \(aqAccept:\(aq
  24. (no data on the right side of the colon), the internally used header is
  25. disabled/removed. With this option you can add new headers, replace internal
  26. headers and remove internal headers. To add a header with no content (nothing
  27. to the right side of the colon), use the form \(aqname;\(aq (note the ending
  28. semicolon).
  29. The headers included in the linked list \fBmust not\fP be CRLF\-terminated,
  30. because libcurl adds CRLF after each header item itself. Failure to comply
  31. with this might result in strange behavior. libcurl passes on the verbatim
  32. strings you give it, without any filter or other safe guards. That includes
  33. white space and control characters.
  34. The first line in an HTTP request (containing the method, usually a GET or
  35. POST) is not a header and cannot be replaced using this option. Only the lines
  36. following the request\-line are headers. Adding this method line in this list
  37. of headers only causes your request to send an invalid header. Use
  38. \fICURLOPT_CUSTOMREQUEST(3)\fP to change the method.
  39. When this option is passed to \fIcurl_easy_setopt(3)\fP, libcurl does not copy
  40. the entire list so you \fBmust\fP keep it around until you no longer use this
  41. \fIhandle\fP for a transfer before you call \fIcurl_slist_free_all(3)\fP on
  42. the list.
  43. Pass a NULL to this option to reset back to no custom headers.
  44. The most commonly replaced HTTP headers have "shortcuts" in the options
  45. \fICURLOPT_COOKIE(3)\fP, \fICURLOPT_USERAGENT(3)\fP and
  46. \fICURLOPT_REFERER(3)\fP. We recommend using those.
  47. There is an alternative option that sets or replaces headers only for requests
  48. that are sent with CONNECT to a proxy: \fICURLOPT_PROXYHEADER(3)\fP. Use
  49. \fICURLOPT_HEADEROPT(3)\fP to control the behavior.
  50. .SH SPECIFIC HTTP HEADERS
  51. Setting some specific headers causes libcurl to act differently.
  52. .IP Host:
  53. The specified hostname is used for cookie matching if the cookie engine is
  54. also enabled for this transfer. If the request is done over HTTP/2 or HTTP/3,
  55. the custom hostname is instead used in the ":authority" header field and
  56. Host: is not sent at all over the wire.
  57. .IP "Transfer-Encoding: chunked"
  58. Tells libcurl the upload is to be done using this chunked encoding instead of
  59. providing the Content\-Length: field in the request.
  60. .SH SPECIFIC MIME HEADERS
  61. When used to build a MIME email for IMAP or SMTP, the following document\-level
  62. headers can be set to override libcurl\-generated values:
  63. .IP Mime-Version:
  64. Tells the parser at the receiving site how to interpret the MIME framing.
  65. It defaults to "1.0" and should normally not be altered.
  66. .IP Content-Type:
  67. Indicates the document\(aqs global structure type. By default, libcurl sets it
  68. to "multipart/mixed", describing a document made of independent parts. When a
  69. MIME mail is only composed of alternative representations of the same data
  70. (i.e.: HTML and plain text), this header must be set to "multipart/alternative".
  71. In all cases the value must be of the form "multipart/*" to respect the
  72. document structure and may not include the "boundary=" parameter.
  73. .PP
  74. Other specific headers that do not have a libcurl default value but are
  75. strongly desired by mail delivery and user agents should also be included.
  76. These are \fIFrom:\fP, \fITo:\fP, \fIDate:\fP and \fISubject:\fP among others and their
  77. presence and value is generally checked by anti\-spam utilities.
  78. .SH SECURITY CONCERNS
  79. By default, this option makes libcurl send the given headers in all HTTP
  80. requests done by this handle. You should therefore use this option with
  81. caution if you for example connect to the remote site using a proxy and a
  82. CONNECT request, you should to consider if that proxy is supposed to also get
  83. the headers. They may be private or otherwise sensitive to leak.
  84. Use \fICURLOPT_HEADEROPT(3)\fP to make the headers only get sent to where you
  85. intend them to get sent.
  86. Custom headers are sent in all requests done by the easy handle, which implies
  87. that if you tell libcurl to follow redirects
  88. (\fICURLOPT_FOLLOWLOCATION(3)\fP), the same set of custom headers is sent in
  89. the subsequent request. Redirects can of course go to other hosts and thus
  90. those servers get all the contents of your custom headers too.
  91. Starting in 7.58.0, libcurl specifically prevents "Authorization:" headers
  92. from being sent to other hosts than the first used one, unless specifically
  93. permitted with the \fICURLOPT_UNRESTRICTED_AUTH(3)\fP option.
  94. Starting in 7.64.0, libcurl specifically prevents "Cookie:" headers from being
  95. sent to other hosts than the first used one, unless specifically permitted
  96. with the \fICURLOPT_UNRESTRICTED_AUTH(3)\fP option.
  97. .SH DEFAULT
  98. NULL
  99. .SH PROTOCOLS
  100. This functionality affects http, imap and smtp
  101. .SH EXAMPLE
  102. .nf
  103. int main(void)
  104. {
  105. CURL *curl = curl_easy_init();
  106. struct curl_slist *list = NULL;
  107. if(curl) {
  108. curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
  109. list = curl_slist_append(list, "Shoesize: 10");
  110. list = curl_slist_append(list, "Accept:");
  111. curl_easy_setopt(curl, CURLOPT_HTTPHEADER, list);
  112. curl_easy_perform(curl);
  113. curl_slist_free_all(list); /* free the list */
  114. }
  115. }
  116. .fi
  117. .SH HISTORY
  118. Use for MIME mail added in 7.56.0.
  119. .SH AVAILABILITY
  120. Added in curl 7.1
  121. .SH RETURN VALUE
  122. Returns CURLE_OK if HTTP is supported, and CURLE_UNKNOWN_OPTION if not.
  123. .SH SEE ALSO
  124. .BR CURLOPT_CUSTOMREQUEST (3),
  125. .BR CURLOPT_HEADER (3),
  126. .BR CURLOPT_HEADEROPT (3),
  127. .BR CURLOPT_MIMEPOST (3),
  128. .BR CURLOPT_PROXYHEADER (3),
  129. .BR curl_mime_init (3)