1---
2c: Copyright (C) Daniel Stenberg, <daniel.se>, et al.
3SPDX-License-Identifier: curl
4Title: CURLOPT_HEADERDATA
5Section: 3
6Source: libcurl
7See-also:
8  - CURLOPT_HEADERFUNCTION (3)
9  - CURLOPT_WRITEFUNCTION (3)
10  - curl_easy_header (3)
11---
12
13# NAME
14
15CURLOPT_HEADERDATA - pointer to pass to header callback
16
17# SYNOPSIS
18
19~~~c
20#include <curl/curl.h>
21
22CURLcode curl_easy_setopt(CURL *handle, CURLOPT_HEADERDATA, void *pointer);
23~~~
24
25# DESCRIPTION
26
27Pass a *pointer* to be used to write the header part of the received data
28to.
29
30If CURLOPT_WRITEFUNCTION(3) or CURLOPT_HEADERFUNCTION(3) is used,
31*pointer* is passed in to the respective callback.
32
33If neither of those options are set, *pointer* must be a valid FILE * and
34it is used by a plain fwrite() to write headers to.
35
36If you are using libcurl as a win32 DLL, you **MUST** use a
37CURLOPT_WRITEFUNCTION(3) or CURLOPT_HEADERFUNCTION(3) if you set
38this option or you might experience crashes.
39
40# DEFAULT
41
42NULL
43
44# PROTOCOLS
45
46All
47
48# EXAMPLE
49
50~~~c
51struct my_info {
52  int shoesize;
53  char *secret;
54};
55
56static size_t header_callback(char *buffer, size_t size,
57                              size_t nitems, void *userdata)
58{
59  struct my_info *i = userdata;
60  printf("shoe size: %d\n", i->shoesize);
61  /* now this callback can access the my_info struct */
62
63  return nitems * size;
64}
65
66int main(void)
67{
68  CURL *curl = curl_easy_init();
69  if(curl) {
70    struct my_info my = { 10, "the cookies are in the cupboard" };
71    curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
72
73    curl_easy_setopt(curl, CURLOPT_HEADERFUNCTION, header_callback);
74
75    /* pass in custom data to the callback */
76    curl_easy_setopt(curl, CURLOPT_HEADERDATA, &my);
77
78    curl_easy_perform(curl);
79  }
80}
81~~~
82
83# AVAILABILITY
84
85Always
86
87# RETURN VALUE
88
89Returns CURLE_OK
90