curl_easy_header.3 6.3 KB

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