curl_pushheader_byname.3 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. .\" generated by cd2nroff 0.1 from curl_pushheader_byname.md
  2. .TH curl_pushheader_byname 3 "2025-01-17" libcurl
  3. .SH NAME
  4. curl_pushheader_byname \- get a push header by name
  5. .SH SYNOPSIS
  6. .nf
  7. #include <curl/curl.h>
  8. char *curl_pushheader_byname(struct curl_pushheaders *h, const char *name);
  9. .fi
  10. .SH DESCRIPTION
  11. This is a function that is only functional within a
  12. \fICURLMOPT_PUSHFUNCTION(3)\fP callback. It makes no sense to try to use it
  13. elsewhere and it has no function then.
  14. It returns the value for the given header field name (or NULL) for the
  15. incoming server push request. This is a shortcut so that the application does
  16. not have to loop through all headers to find the one it is interested in. The
  17. data this function points to is freed when this callback returns. If more than
  18. one header field use the same name, this returns only the first one.
  19. .SH PROTOCOLS
  20. This functionality affects http only
  21. .SH EXAMPLE
  22. .nf
  23. #include <string.h> /* for strncmp */
  24. static int push_cb(CURL *parent,
  25. CURL *easy,
  26. size_t num_headers,
  27. struct curl_pushheaders *headers,
  28. void *clientp)
  29. {
  30. char *headp;
  31. int *transfers = (int *)clientp;
  32. FILE *out;
  33. headp = curl_pushheader_byname(headers, ":path");
  34. if(headp && !strncmp(headp, "/push-", 6)) {
  35. fprintf(stderr, "The PATH is %s\\n", headp);
  36. /* save the push here */
  37. out = fopen("pushed-stream", "wb");
  38. /* write to this file */
  39. curl_easy_setopt(easy, CURLOPT_WRITEDATA, out);
  40. (*transfers)++; /* one more */
  41. return CURL_PUSH_OK;
  42. }
  43. return CURL_PUSH_DENY;
  44. }
  45. int main(void)
  46. {
  47. int counter;
  48. CURLM *multi = curl_multi_init();
  49. curl_multi_setopt(multi, CURLMOPT_PUSHFUNCTION, push_cb);
  50. curl_multi_setopt(multi, CURLMOPT_PUSHDATA, &counter);
  51. }
  52. .fi
  53. .SH AVAILABILITY
  54. Added in curl 7.44.0
  55. .SH RETURN VALUE
  56. Returns a pointer to the header field content or NULL.
  57. .SH SEE ALSO
  58. .BR CURLMOPT_PUSHFUNCTION (3),
  59. .BR curl_pushheader_bynum (3)