The header callback is set with
curl_easy_setopt(handle, CURLOPT_HEADERFUNCTION, header_callback);
header_callback function must match this prototype:
size_t header_callback(char *ptr, size_t size, size_t nmemb, void *userdata);
This callback function gets called by libcurl as soon as a header has been received. ptr points to the delivered data, and the size of that data is size multiplied with nmemb. libcurl buffers headers and delivers only "full" headers, one by one, to this callback.
The data passed to this function will not be zero terminated! You cannot, for example, use printf's "%s" operator to display the contents nor strcpy to copy it.
This callback should return the number of bytes actually taken care of. If
that number differs from the number passed to your callback function, it
signals an error condition to the library. This will cause the transfer to
abort and the libcurl function used will return
The user pointer passed in to the callback in the userdata argument is set
curl_easy_setopt(handle, CURLOPT_HEADERDATA, custom_pointer);