quickjs-tart

quickjs-based runtime for wallet-core logic
Log | Files | Refs | README | LICENSE

CURLOPT_HEADERDATA.md (1961B)


      1 ---
      2 c: Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
      3 SPDX-License-Identifier: curl
      4 Title: CURLOPT_HEADERDATA
      5 Section: 3
      6 Source: libcurl
      7 See-also:
      8   - CURLOPT_HEADERFUNCTION (3)
      9   - CURLOPT_WRITEFUNCTION (3)
     10   - curl_easy_header (3)
     11 Protocol:
     12   - All
     13 Added-in: 7.10
     14 ---
     15 
     16 # NAME
     17 
     18 CURLOPT_HEADERDATA - pointer to pass to header callback
     19 
     20 # SYNOPSIS
     21 
     22 ~~~c
     23 #include <curl/curl.h>
     24 
     25 CURLcode curl_easy_setopt(CURL *handle, CURLOPT_HEADERDATA, void *pointer);
     26 ~~~
     27 
     28 # DESCRIPTION
     29 
     30 Pass a *pointer* to be used to write the header part of the received data
     31 to.
     32 
     33 If CURLOPT_WRITEFUNCTION(3) or CURLOPT_HEADERFUNCTION(3) is used,
     34 *pointer* is passed in to the respective callback.
     35 
     36 If neither of those options are set, *pointer* must be a valid FILE * and
     37 it is used by a plain fwrite() to write headers to.
     38 
     39 If you are using libcurl as a Windows DLL, you **MUST** use a
     40 CURLOPT_WRITEFUNCTION(3) or CURLOPT_HEADERFUNCTION(3) if you set
     41 this option or you might experience crashes.
     42 
     43 # DEFAULT
     44 
     45 NULL
     46 
     47 # %PROTOCOLS%
     48 
     49 # EXAMPLE
     50 
     51 ~~~c
     52 struct my_info {
     53   int shoesize;
     54   char *secret;
     55 };
     56 
     57 static 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 
     67 int 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 
     88 curl_easy_setopt(3) returns a CURLcode indicating success or error.
     89 
     90 CURLE_OK (0) means everything was OK, non-zero means an error occurred, see
     91 libcurl-errors(3).