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