CURLOPT_HTTPHEADER.3 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. .\" **************************************************************************
  2. .\" * _ _ ____ _
  3. .\" * Project ___| | | | _ \| |
  4. .\" * / __| | | | |_) | |
  5. .\" * | (__| |_| | _ <| |___
  6. .\" * \___|\___/|_| \_\_____|
  7. .\" *
  8. .\" * Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
  9. .\" *
  10. .\" * This software is licensed as described in the file COPYING, which
  11. .\" * you should have received as part of this distribution. The terms
  12. .\" * are also available at https://curl.se/docs/copyright.html.
  13. .\" *
  14. .\" * You may opt to use, copy, modify, merge, publish, distribute and/or sell
  15. .\" * copies of the Software, and permit persons to whom the Software is
  16. .\" * furnished to do so, under the terms of the COPYING file.
  17. .\" *
  18. .\" * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
  19. .\" * KIND, either express or implied.
  20. .\" *
  21. .\" * SPDX-License-Identifier: curl
  22. .\" *
  23. .\" **************************************************************************
  24. .\"
  25. .TH CURLOPT_HTTPHEADER 3 "17 Jun 2014" libcurl libcurl
  26. .SH NAME
  27. CURLOPT_HTTPHEADER \- set of HTTP headers
  28. .SH SYNOPSIS
  29. .nf
  30. #include <curl/curl.h>
  31. CURLcode curl_easy_setopt(CURL *handle, CURLOPT_HTTPHEADER,
  32. struct curl_slist *headers);
  33. .fi
  34. .SH DESCRIPTION
  35. Pass a pointer to a linked list of HTTP headers to pass to the server and/or
  36. proxy in your HTTP request. The same list can be used for both host and proxy
  37. requests!
  38. When used within an IMAP or SMTP request to upload a MIME mail, the given
  39. header list establishes the document-level MIME headers to prepend to the
  40. uploaded document described by \fICURLOPT_MIMEPOST(3)\fP. This does not affect
  41. raw mail uploads.
  42. The linked list should be a fully valid list of \fBstruct curl_slist\fP
  43. structs properly filled in. Use \fIcurl_slist_append(3)\fP to create the list
  44. and \fIcurl_slist_free_all(3)\fP to clean up an entire list. If you add a
  45. header that is otherwise generated and used by libcurl internally, your added
  46. one will be used instead. If you add a header with no content as in 'Accept:'
  47. (no data on the right side of the colon), the internally used header will get
  48. disabled. With this option you can add new headers, replace internal headers
  49. and remove internal headers. To add a header with no content (nothing to the
  50. right side of the colon), use the form 'name;' (note the ending semicolon).
  51. The headers included in the linked list \fBmust not\fP be CRLF-terminated,
  52. because libcurl adds CRLF after each header item. Failure to comply with this
  53. will result in strange bugs because the server will most likely ignore part of
  54. the headers you specified.
  55. The first line in an HTTP request (containing the method, usually a GET or
  56. POST) is not a header and cannot be replaced using this option. Only the lines
  57. following the request-line are headers. Adding this method line in this list
  58. of headers will only cause your request to send an invalid header. Use
  59. \fICURLOPT_CUSTOMREQUEST(3)\fP to change the method.
  60. When this option is passed to \fIcurl_easy_setopt(3)\fP, libcurl will not copy
  61. the entire list so you \fBmust\fP keep it around until you no longer use this
  62. \fIhandle\fP for a transfer before you call \fIcurl_slist_free_all(3)\fP on
  63. the list.
  64. Pass a NULL to this option to reset back to no custom headers.
  65. The most commonly replaced HTTP headers have "shortcuts" in the options
  66. \fICURLOPT_COOKIE(3)\fP, \fICURLOPT_USERAGENT(3)\fP and
  67. \fICURLOPT_REFERER(3)\fP. We recommend using those.
  68. There's an alternative option that sets or replaces headers only for requests
  69. that are sent with CONNECT to a proxy: \fICURLOPT_PROXYHEADER(3)\fP. Use
  70. \fICURLOPT_HEADEROPT(3)\fP to control the behavior.
  71. .SH SPECIFIC HTTP HEADERS
  72. Setting some specific headers will cause libcurl to act differently.
  73. .IP "Host:"
  74. The specified host name will be used for cookie matching if the cookie engine
  75. is also enabled for this transfer. If the request is done over HTTP/2 or
  76. HTTP/3, the custom host name will instead be used in the ":authority" header
  77. field and Host: will not be sent at all over the wire.
  78. .IP "Transfer-Encoding: chunked"
  79. Tells libcurl the upload is to be done using this chunked encoding instead of
  80. providing the Content-Length: field in the request.
  81. .SH SPECIFIC MIME HEADERS
  82. When used to build a MIME e-mail for IMAP or SMTP, the following
  83. document-level headers can be set to override libcurl-generated values:
  84. .IP "Mime-Version:"
  85. Tells the parser at the receiving site how to interpret the MIME framing.
  86. It defaults to "1.0" and should normally not be altered.
  87. .IP "Content-Type:"
  88. Indicates the document's global structure type. By default, libcurl sets it
  89. to "multipart/mixed", describing a document made of independent parts. When a
  90. MIME mail is only composed of alternative representations of the same data
  91. (i.e.: HTML and plain text), this header must be set to "multipart/alternative".
  92. In all cases the value must be of the form "multipart/*" to respect the
  93. document structure and may not include the "boundary=" parameter.
  94. .P
  95. Other specific headers that do not have a libcurl default value but are
  96. strongly desired by mail delivery and user agents should also be included.
  97. These are "From:", "To:", "Date:" and "Subject:" among others and their
  98. presence and value is generally checked by anti-spam utilities.
  99. .SH SECURITY CONCERNS
  100. By default, this option makes libcurl send the given headers in all HTTP
  101. requests done by this handle. You should therefore use this option with
  102. caution if you for example connect to the remote site using a proxy and a
  103. CONNECT request, you should to consider if that proxy is supposed to also get
  104. the headers. They may be private or otherwise sensitive to leak.
  105. Use \fICURLOPT_HEADEROPT(3)\fP to make the headers only get sent to where you
  106. intend them to get sent.
  107. Custom headers are sent in all requests done by the easy handles, which
  108. implies that if you tell libcurl to follow redirects
  109. (\fICURLOPT_FOLLOWLOCATION(3)\fP), the same set of custom headers will be sent
  110. in the subsequent request. Redirects can of course go to other hosts and thus
  111. those servers will get all the contents of your custom headers too.
  112. Starting in 7.58.0, libcurl will specifically prevent "Authorization:" headers
  113. from being sent to other hosts than the first used one, unless specifically
  114. permitted with the \fICURLOPT_UNRESTRICTED_AUTH(3)\fP option.
  115. Starting in 7.64.0, libcurl will specifically prevent "Cookie:" headers
  116. from being sent to other hosts than the first used one, unless specifically
  117. permitted with the \fICURLOPT_UNRESTRICTED_AUTH(3)\fP option.
  118. .SH DEFAULT
  119. NULL
  120. .SH PROTOCOLS
  121. HTTP, IMAP and SMTP
  122. .SH EXAMPLE
  123. .nf
  124. CURL *curl = curl_easy_init();
  125. struct curl_slist *list = NULL;
  126. if(curl) {
  127. curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
  128. list = curl_slist_append(list, "Shoesize: 10");
  129. list = curl_slist_append(list, "Accept:");
  130. curl_easy_setopt(curl, CURLOPT_HTTPHEADER, list);
  131. curl_easy_perform(curl);
  132. curl_slist_free_all(list); /* free the list */
  133. }
  134. .fi
  135. .SH AVAILABILITY
  136. As long as HTTP is enabled. Use in MIME mail added in 7.56.0.
  137. .SH RETURN VALUE
  138. Returns CURLE_OK if HTTP is supported, and CURLE_UNKNOWN_OPTION if not.
  139. .SH "SEE ALSO"
  140. .BR CURLOPT_CUSTOMREQUEST "(3), " CURLOPT_HEADEROPT "(3), "
  141. .BR CURLOPT_PROXYHEADER "(3), " CURLOPT_HEADER "(3), "
  142. .BR CURLOPT_MIMEPOST "(3), " curl_mime_init "(3)"