1CURLOPT_HEADERDATA(3)      curl_easy_setopt options      CURLOPT_HEADERDATA(3)
2
3
4

NAME

6       CURLOPT_HEADERDATA - pointer to pass to header callback
7

SYNOPSIS

9       #include <curl/curl.h>
10
11       CURLcode curl_easy_setopt(CURL *handle, CURLOPT_HEADERDATA, void *pointer);
12

DESCRIPTION

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

DEFAULT

24       NULL
25

PROTOCOLS

27       All
28

EXAMPLE

30       struct my_info {
31         int shoesize;
32         char *secret;
33       };
34
35       static size_t header_callback(char *buffer, size_t size,
36                                     size_t nitems, void *userdata)
37       {
38         struct my_info *i = (struct my_info *)userdata;
39
40         /* now this callback can access the my_info struct */
41
42         return nitems * size;
43       }
44
45       CURL *curl = curl_easy_init();
46       if(curl) {
47         struct my_info my = { 10, "the cookies are in the cupboard" };
48         curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
49
50         curl_easy_setopt(curl, CURLOPT_HEADERFUNCTION, header_callback);
51
52         /* pass in custom data to the callback */
53         curl_easy_setopt(curl, CURLOPT_HEADERDATA, &my);
54
55         curl_easy_perform(curl);
56       }
57

AVAILABILITY

59       Always
60

RETURN VALUE

62       Returns CURLE_OK
63

SEE ALSO

65       CURLOPT_HEADERFUNCTION(3), CURLOPT_WRITEFUNCTION(3),
66
67
68
69libcurl 7.85.0                   May 17, 2022            CURLOPT_HEADERDATA(3)
Impressum