1CURLOPT_HEADERDATA(3) curl_easy_setopt options CURLOPT_HEADERDATA(3)
2
3
4
6 CURLOPT_HEADERDATA - pointer to pass to header callback
7
9 #include <curl/curl.h>
10
11 CURLcode curl_easy_setopt(CURL *handle, CURLOPT_HEADERDATA, void *pointer);
12
14 Pass a pointer to be used to write the header part of the received data
15 to.
16
17 If CURLOPT_WRITEFUNCTION(3) or CURLOPT_HEADERFUNCTION(3) is used,
18 pointer will be passed in to the respective callback.
19
20 If neither of those options are set, pointer must be a valid FILE * and
21 it will be used by a plain fwrite() to write headers to.
22
23 If you are using libcurl as a win32 DLL, you MUST use a CURLOPT_WRITE‐
24 FUNCTION(3) or CURLOPT_HEADERFUNCTION(3) if you set this option or you
25 will experience crashes.
26
28 NULL
29
31 All
32
34 struct my_info {
35 int shoesize;
36 char *secret;
37 };
38
39 static size_t header_callback(char *buffer, size_t size,
40 size_t nitems, void *userdata)
41 {
42 struct my_info *i = (struct my_info *)userdata;
43
44 /* now this callback can access the my_info struct */
45
46 return nitems * size;
47 }
48
49 CURL *curl = curl_easy_init();
50 if(curl) {
51 struct my_info my = { 10, "the cookies are in the cupboard" };
52 curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
53
54 curl_easy_setopt(curl, CURLOPT_HEADERFUNCTION, header_callback);
55
56 /* pass in custom data to the callback */
57 curl_easy_setopt(curl, CURLOPT_HEADERDATA, &my);
58
59 curl_easy_perform(curl);
60 }
61
63 Always
64
66 Returns CURLE_OK
67
69 CURLOPT_HEADERFUNCTION(3), CURLOPT_WRITEFUNCTION(3),
70
71
72
73libcurl 8.0.1 January 05, 2023 CURLOPT_HEADERDATA(3)