CURLOPT_HEADERDATA.3 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. .\" generated by cd2nroff 0.1 from CURLOPT_HEADERDATA.md
  2. .TH CURLOPT_HEADERDATA 3 "2025-01-17" libcurl
  3. .SH NAME
  4. CURLOPT_HEADERDATA \- pointer to pass to header callback
  5. .SH SYNOPSIS
  6. .nf
  7. #include <curl/curl.h>
  8. CURLcode curl_easy_setopt(CURL *handle, CURLOPT_HEADERDATA, void *pointer);
  9. .fi
  10. .SH DESCRIPTION
  11. Pass a \fIpointer\fP to be used to write the header part of the received data
  12. to.
  13. If \fICURLOPT_WRITEFUNCTION(3)\fP or \fICURLOPT_HEADERFUNCTION(3)\fP is used,
  14. \fIpointer\fP is passed in to the respective callback.
  15. If neither of those options are set, \fIpointer\fP must be a valid FILE * and
  16. it is used by a plain fwrite() to write headers to.
  17. If you are using libcurl as a win32 DLL, you \fBMUST\fP use a
  18. \fICURLOPT_WRITEFUNCTION(3)\fP or \fICURLOPT_HEADERFUNCTION(3)\fP if you set
  19. this option or you might experience crashes.
  20. .SH DEFAULT
  21. NULL
  22. .SH PROTOCOLS
  23. This functionality affects all supported protocols
  24. .SH EXAMPLE
  25. .nf
  26. struct my_info {
  27. int shoesize;
  28. char *secret;
  29. };
  30. static size_t header_callback(char *buffer, size_t size,
  31. size_t nitems, void *userdata)
  32. {
  33. struct my_info *i = userdata;
  34. printf("shoe size: %d\\n", i->shoesize);
  35. /* now this callback can access the my_info struct */
  36. return nitems * size;
  37. }
  38. int main(void)
  39. {
  40. CURL *curl = curl_easy_init();
  41. if(curl) {
  42. struct my_info my = { 10, "the cookies are in the cupboard" };
  43. curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
  44. curl_easy_setopt(curl, CURLOPT_HEADERFUNCTION, header_callback);
  45. /* pass in custom data to the callback */
  46. curl_easy_setopt(curl, CURLOPT_HEADERDATA, &my);
  47. curl_easy_perform(curl);
  48. }
  49. }
  50. .fi
  51. .SH AVAILABILITY
  52. Added in curl 7.10
  53. .SH RETURN VALUE
  54. Returns CURLE_OK
  55. .SH SEE ALSO
  56. .BR CURLOPT_HEADERFUNCTION (3),
  57. .BR CURLOPT_WRITEFUNCTION (3),
  58. .BR curl_easy_header (3)