curl_easy_nextheader.3 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. .\" generated by cd2nroff 0.1 from curl_easy_nextheader.md
  2. .TH curl_easy_nextheader 3 "2025-01-17" libcurl
  3. .SH NAME
  4. curl_easy_nextheader \- get the next HTTP header
  5. .SH SYNOPSIS
  6. .nf
  7. #include <curl/curl.h>
  8. struct curl_header *curl_easy_nextheader(CURL *easy,
  9. unsigned int origin,
  10. int request,
  11. struct curl_header *prev);
  12. .fi
  13. .SH DESCRIPTION
  14. This function lets an application iterate over all previously received HTTP
  15. headers.
  16. The \fIorigin\fP argument is for specifying which headers to receive, as a single
  17. HTTP transfer might provide headers from several different places and they may
  18. then have different importance to the user and headers using the same name
  19. might be used. The \fIorigin\fP is a bitmask for what header sources you want. See
  20. the \fIcurl_easy_header(3)\fP man page for the origin descriptions.
  21. The \fIrequest\fP argument tells libcurl from which request you want headers
  22. from. A single transfer might consist of a series of HTTP requests and this
  23. argument lets you specify which particular individual request you want the
  24. headers from. 0 being the first request and then the number increases for
  25. further redirects or when multi\-state authentication is used. Passing in \-1 is
  26. a shortcut to "the last" request in the series, independently of the actual
  27. amount of requests used.
  28. It is suggested that you pass in the same \fBorigin\fP and \fBrequest\fP when
  29. iterating over a range of headers as changing the value mid\-loop might give
  30. you unexpected results.
  31. If \fIprev\fP is NULL, this function returns a pointer to the first header stored
  32. within the given scope (origin + request).
  33. If \fIprev\fP is a pointer to a previously returned header struct,
  34. \fIcurl_easy_nextheader(3)\fP returns a pointer the next header stored within the
  35. given scope. This way, an application can iterate over all available headers.
  36. The memory for the struct this points to, is owned and managed by libcurl and
  37. is associated with the easy handle. Applications must copy the data if they
  38. want it to survive subsequent API calls or the life\-time of the easy handle.
  39. .SH PROTOCOLS
  40. This functionality affects http only
  41. .SH EXAMPLE
  42. .nf
  43. int main(void)
  44. {
  45. struct curl_header *prev = NULL;
  46. struct curl_header *h;
  47. CURL *curl = curl_easy_init();
  48. if(curl) {
  49. curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
  50. curl_easy_perform(curl);
  51. /* extract the normal headers from the first request */
  52. while((h = curl_easy_nextheader(curl, CURLH_HEADER, 0, prev))) {
  53. printf("%s: %s\\n", h->name, h->value);
  54. prev = h;
  55. }
  56. /* extract the normal headers + 1xx + trailers from the last request */
  57. unsigned int origin = CURLH_HEADER| CURLH_1XX | CURLH_TRAILER;
  58. while((h = curl_easy_nextheader(curl, origin, -1, prev))) {
  59. printf("%s: %s\\n", h->name, h->value);
  60. prev = h;
  61. }
  62. }
  63. }
  64. .fi
  65. .SH AVAILABILITY
  66. Added in curl 7.83.0
  67. .SH RETURN VALUE
  68. This function returns the next header, or NULL when there are no more
  69. (matching) headers or an error occurred.
  70. If this function returns NULL when \fIprev\fP was set to NULL, then there are no
  71. headers available within the scope to return.
  72. .SH SEE ALSO
  73. .BR curl_easy_header (3),
  74. .BR curl_easy_perform (3)