curl_pushheader_byname.3 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. .\" **************************************************************************
  2. .\" * _ _ ____ _
  3. .\" * Project ___| | | | _ \| |
  4. .\" * / __| | | | |_) | |
  5. .\" * | (__| |_| | _ <| |___
  6. .\" * \___|\___/|_| \_\_____|
  7. .\" *
  8. .\" * Copyright (C) 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. .\" * SPDX-License-Identifier: curl
  22. .\" *
  23. .\" **************************************************************************
  24. .TH curl_pushheader_byname 3 "9 Jun 2023" "libcurl" "libcurl"
  25. .SH NAME
  26. curl_pushheader_byname - get a push header by name
  27. .SH SYNOPSIS
  28. .nf
  29. #include <curl/curl.h>
  30. char *curl_pushheader_byname(struct curl_pushheaders *h, const char *name);
  31. .fi
  32. .SH DESCRIPTION
  33. This is a function that is only functional within a
  34. \fICURLMOPT_PUSHFUNCTION(3)\fP callback. It makes no sense to try to use it
  35. elsewhere and it has no function then.
  36. It returns the value for the given header field name (or NULL) for the
  37. incoming server push request. This is a shortcut so that the application does
  38. not have to loop through all headers to find the one it is interested in. The
  39. data this function points to is freed when this callback returns. If more than
  40. one header field use the same name, this returns only the first one.
  41. .SH EXAMPLE
  42. .nf
  43. #include <string.h> /* for strncmp */
  44. static int push_cb(CURL *parent,
  45. CURL *easy,
  46. size_t num_headers,
  47. struct curl_pushheaders *headers,
  48. void *clientp)
  49. {
  50. char *headp;
  51. int *transfers = (int *)clientp;
  52. FILE *out;
  53. headp = curl_pushheader_byname(headers, ":path");
  54. if(headp && !strncmp(headp, "/push-", 6)) {
  55. fprintf(stderr, "The PATH is %s\\n", headp);
  56. /* save the push here */
  57. out = fopen("pushed-stream", "wb");
  58. /* write to this file */
  59. curl_easy_setopt(easy, CURLOPT_WRITEDATA, out);
  60. (*transfers)++; /* one more */
  61. return CURL_PUSH_OK;
  62. }
  63. return CURL_PUSH_DENY;
  64. }
  65. int main(void)
  66. {
  67. int counter;
  68. CURLM *multi = curl_multi_init();
  69. curl_multi_setopt(multi, CURLMOPT_PUSHFUNCTION, push_cb);
  70. curl_multi_setopt(multi, CURLMOPT_PUSHDATA, &counter);
  71. }
  72. .fi
  73. .SH AVAILABILITY
  74. Added in 7.44.0
  75. .SH RETURN VALUE
  76. Returns a pointer to the header field content or NULL.
  77. .SH "SEE ALSO"
  78. .BR CURLMOPT_PUSHFUNCTION (3),
  79. .BR curl_pushheader_bynum (3)