curl_easy_header.3 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. .\" generated by cd2nroff 0.1 from curl_easy_header.md
  2. .TH curl_easy_header 3 "2025-01-17" libcurl
  3. .SH NAME
  4. curl_easy_header \- get an HTTP header
  5. .SH SYNOPSIS
  6. .nf
  7. #include <curl/curl.h>
  8. CURLHcode curl_easy_header(CURL *easy,
  9. const char *name,
  10. size_t index,
  11. unsigned int origin,
  12. int request,
  13. struct curl_header **hout);
  14. .fi
  15. .SH DESCRIPTION
  16. \fIcurl_easy_header(3)\fP returns a pointer to a "curl_header" struct in \fBhout\fP
  17. with data for the HTTP response header \fIname\fP. The case insensitive
  18. null\-terminated header name should be specified without colon.
  19. \fIindex\fP 0 means asking for the first instance of the header. If the returned
  20. header struct has \fBamount\fP set larger than 1, it means there are more
  21. instances of the same header name available to get. Asking for a too big index
  22. makes \fBCURLHE_BADINDEX\fP get returned.
  23. The \fIorigin\fP argument is for specifying which headers to receive, as a single
  24. HTTP transfer might provide headers from several different places and they may
  25. then have different importance to the user and headers using the same name
  26. might be used. The \fIorigin\fP is a bitmask for what header sources you want. See
  27. the descriptions below.
  28. The \fIrequest\fP argument tells libcurl from which request you want headers
  29. from. A single transfer might consist of a series of HTTP requests and this
  30. argument lets you specify which particular individual request you want the
  31. headers from. 0 being the first request and then the number increases for
  32. further redirects or when multi\-state authentication is used. Passing in \-1 is
  33. a shortcut to "the last" request in the series, independently of the actual
  34. amount of requests used.
  35. libcurl stores and provides the actually used "correct" headers. If for
  36. example two headers with the same name arrive and the latter overrides the
  37. former, then only the latter is provided. If the first header survives the
  38. second, then only the first one is provided. An application using this API
  39. does not have to bother about multiple headers used wrongly.
  40. The memory for the returned struct is associated with the easy handle and
  41. subsequent calls to \fIcurl_easy_header(3)\fP clobber the struct used in the
  42. previous calls for the same easy handle. Applications need to copy the data if
  43. it wants to keep it around. The memory used for the struct gets freed with
  44. calling \fIcurl_easy_cleanup(3)\fP of the easy handle.
  45. The first line in an HTTP response is called the status line. It is not
  46. considered a header by this function. Headers are the "name: value" lines
  47. following the status.
  48. This function can be used before (all) headers have been received and is fine
  49. to call from within libcurl callbacks. It returns the state of the headers at
  50. the time it is called.
  51. .SH The header struct
  52. .nf
  53. struct curl_header {
  54. char *name;
  55. char *value;
  56. size_t amount;
  57. size_t index;
  58. unsigned int origin;
  59. void *anchor;
  60. };
  61. .fi
  62. The data \fBname\fP field points to, is the same as the requested name, but
  63. might have a different case.
  64. The data \fBvalue\fP field points to, comes exactly as delivered over the
  65. network but with leading and trailing whitespace and newlines stripped
  66. off. The \fIvalue\fP data is null\-terminated. For legacy HTTP/1 "folded headers",
  67. this API provides the full single value in an unfolded manner with a single
  68. whitespace between the lines.
  69. \fBamount\fP is how many headers using this name that exist, within the origin
  70. and request scope asked for.
  71. \fBindex\fP is the zero based entry number of this particular header, which in
  72. case this header was used more than once in the requested scope can be larger
  73. than 0 but is always less than \fBamount\fP.
  74. The \fBorigin\fP field in the "curl_header" struct has one of the origin bits
  75. set, indicating where from the header originates. At the time of this writing,
  76. there are 5 bits with defined use. The undocumented 27 remaining bits are
  77. reserved for future use and must not be assumed to have any particular value.
  78. \fBanchor\fP is a private handle used by libcurl internals. Do not modify.
  79. .SH ORIGINS
  80. .IP CURLH_HEADER
  81. The header arrived as a header from the server.
  82. .IP CURLH_TRAILER
  83. The header arrived as a trailer. A header that arrives after the body.
  84. .IP CURLH_CONNECT
  85. The header arrived in a CONNECT response. A CONNECT request is being done to
  86. setup a transfer "through" an HTTP(S) proxy.
  87. .IP CURLH_1XX
  88. The header arrived in an HTTP 1xx response. A 1xx response is an "intermediate"
  89. response that might happen before the "real" response.
  90. .IP CURLH_PSEUDO
  91. The header is an HTTP/2 or HTTP/3 pseudo header
  92. .SH PROTOCOLS
  93. This functionality affects http only
  94. .SH EXAMPLE
  95. .nf
  96. int main(void)
  97. {
  98. struct curl_header *type;
  99. CURL *curl = curl_easy_init();
  100. if(curl) {
  101. CURLHcode h;
  102. curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
  103. curl_easy_perform(curl);
  104. h = curl_easy_header(curl, "Content-Type", 0, CURLH_HEADER, -1, &type);
  105. curl_easy_cleanup(curl);
  106. }
  107. }
  108. .fi
  109. .SH AVAILABILITY
  110. Added in curl 7.83.0
  111. .SH RETURN VALUE
  112. This function returns a CURLHcode indicating success or error.
  113. .SH SEE ALSO
  114. .BR CURLINFO_CONTENT_TYPE (3),
  115. .BR CURLOPT_HEADERFUNCTION (3),
  116. .BR curl_easy_nextheader (3),
  117. .BR curl_easy_perform (3),
  118. .BR libcurl-errors (3)