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