xref: /aosp_15_r20/external/curl/docs/libcurl/opts/CURLOPT_HEADERDATA.md (revision 6236dae45794135f37c4eb022389c904c8b0090d)
1*6236dae4SAndroid Build Coastguard Worker---
2*6236dae4SAndroid Build Coastguard Workerc: Copyright (C) Daniel Stenberg, <[email protected]>, et al.
3*6236dae4SAndroid Build Coastguard WorkerSPDX-License-Identifier: curl
4*6236dae4SAndroid Build Coastguard WorkerTitle: CURLOPT_HEADERDATA
5*6236dae4SAndroid Build Coastguard WorkerSection: 3
6*6236dae4SAndroid Build Coastguard WorkerSource: libcurl
7*6236dae4SAndroid Build Coastguard WorkerSee-also:
8*6236dae4SAndroid Build Coastguard Worker  - CURLOPT_HEADERFUNCTION (3)
9*6236dae4SAndroid Build Coastguard Worker  - CURLOPT_WRITEFUNCTION (3)
10*6236dae4SAndroid Build Coastguard Worker  - curl_easy_header (3)
11*6236dae4SAndroid Build Coastguard WorkerProtocol:
12*6236dae4SAndroid Build Coastguard Worker  - All
13*6236dae4SAndroid Build Coastguard WorkerAdded-in: 7.10
14*6236dae4SAndroid Build Coastguard Worker---
15*6236dae4SAndroid Build Coastguard Worker
16*6236dae4SAndroid Build Coastguard Worker# NAME
17*6236dae4SAndroid Build Coastguard Worker
18*6236dae4SAndroid Build Coastguard WorkerCURLOPT_HEADERDATA - pointer to pass to header callback
19*6236dae4SAndroid Build Coastguard Worker
20*6236dae4SAndroid Build Coastguard Worker# SYNOPSIS
21*6236dae4SAndroid Build Coastguard Worker
22*6236dae4SAndroid Build Coastguard Worker~~~c
23*6236dae4SAndroid Build Coastguard Worker#include <curl/curl.h>
24*6236dae4SAndroid Build Coastguard Worker
25*6236dae4SAndroid Build Coastguard WorkerCURLcode curl_easy_setopt(CURL *handle, CURLOPT_HEADERDATA, void *pointer);
26*6236dae4SAndroid Build Coastguard Worker~~~
27*6236dae4SAndroid Build Coastguard Worker
28*6236dae4SAndroid Build Coastguard Worker# DESCRIPTION
29*6236dae4SAndroid Build Coastguard Worker
30*6236dae4SAndroid Build Coastguard WorkerPass a *pointer* to be used to write the header part of the received data
31*6236dae4SAndroid Build Coastguard Workerto.
32*6236dae4SAndroid Build Coastguard Worker
33*6236dae4SAndroid Build Coastguard WorkerIf CURLOPT_WRITEFUNCTION(3) or CURLOPT_HEADERFUNCTION(3) is used,
34*6236dae4SAndroid Build Coastguard Worker*pointer* is passed in to the respective callback.
35*6236dae4SAndroid Build Coastguard Worker
36*6236dae4SAndroid Build Coastguard WorkerIf neither of those options are set, *pointer* must be a valid FILE * and
37*6236dae4SAndroid Build Coastguard Workerit is used by a plain fwrite() to write headers to.
38*6236dae4SAndroid Build Coastguard Worker
39*6236dae4SAndroid Build Coastguard WorkerIf you are using libcurl as a Windows DLL, you **MUST** use a
40*6236dae4SAndroid Build Coastguard WorkerCURLOPT_WRITEFUNCTION(3) or CURLOPT_HEADERFUNCTION(3) if you set
41*6236dae4SAndroid Build Coastguard Workerthis option or you might experience crashes.
42*6236dae4SAndroid Build Coastguard Worker
43*6236dae4SAndroid Build Coastguard Worker# DEFAULT
44*6236dae4SAndroid Build Coastguard Worker
45*6236dae4SAndroid Build Coastguard WorkerNULL
46*6236dae4SAndroid Build Coastguard Worker
47*6236dae4SAndroid Build Coastguard Worker# %PROTOCOLS%
48*6236dae4SAndroid Build Coastguard Worker
49*6236dae4SAndroid Build Coastguard Worker# EXAMPLE
50*6236dae4SAndroid Build Coastguard Worker
51*6236dae4SAndroid Build Coastguard Worker~~~c
52*6236dae4SAndroid Build Coastguard Workerstruct my_info {
53*6236dae4SAndroid Build Coastguard Worker  int shoesize;
54*6236dae4SAndroid Build Coastguard Worker  char *secret;
55*6236dae4SAndroid Build Coastguard Worker};
56*6236dae4SAndroid Build Coastguard Worker
57*6236dae4SAndroid Build Coastguard Workerstatic size_t header_callback(char *buffer, size_t size,
58*6236dae4SAndroid Build Coastguard Worker                              size_t nitems, void *userdata)
59*6236dae4SAndroid Build Coastguard Worker{
60*6236dae4SAndroid Build Coastguard Worker  struct my_info *i = userdata;
61*6236dae4SAndroid Build Coastguard Worker  printf("shoe size: %d\n", i->shoesize);
62*6236dae4SAndroid Build Coastguard Worker  /* now this callback can access the my_info struct */
63*6236dae4SAndroid Build Coastguard Worker
64*6236dae4SAndroid Build Coastguard Worker  return nitems * size;
65*6236dae4SAndroid Build Coastguard Worker}
66*6236dae4SAndroid Build Coastguard Worker
67*6236dae4SAndroid Build Coastguard Workerint main(void)
68*6236dae4SAndroid Build Coastguard Worker{
69*6236dae4SAndroid Build Coastguard Worker  CURL *curl = curl_easy_init();
70*6236dae4SAndroid Build Coastguard Worker  if(curl) {
71*6236dae4SAndroid Build Coastguard Worker    struct my_info my = { 10, "the cookies are in the cupboard" };
72*6236dae4SAndroid Build Coastguard Worker    curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
73*6236dae4SAndroid Build Coastguard Worker
74*6236dae4SAndroid Build Coastguard Worker    curl_easy_setopt(curl, CURLOPT_HEADERFUNCTION, header_callback);
75*6236dae4SAndroid Build Coastguard Worker
76*6236dae4SAndroid Build Coastguard Worker    /* pass in custom data to the callback */
77*6236dae4SAndroid Build Coastguard Worker    curl_easy_setopt(curl, CURLOPT_HEADERDATA, &my);
78*6236dae4SAndroid Build Coastguard Worker
79*6236dae4SAndroid Build Coastguard Worker    curl_easy_perform(curl);
80*6236dae4SAndroid Build Coastguard Worker  }
81*6236dae4SAndroid Build Coastguard Worker}
82*6236dae4SAndroid Build Coastguard Worker~~~
83*6236dae4SAndroid Build Coastguard Worker
84*6236dae4SAndroid Build Coastguard Worker# %AVAILABILITY%
85*6236dae4SAndroid Build Coastguard Worker
86*6236dae4SAndroid Build Coastguard Worker# RETURN VALUE
87*6236dae4SAndroid Build Coastguard Worker
88*6236dae4SAndroid Build Coastguard WorkerReturns CURLE_OK
89