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