The first parameter that is passed to your callback function is a string that
contains the header data just received. If you pass the optional
argument, the value you pass in
userdata will be passed to your callback function as
a second parameter. The
userdata parameter can be of any type.
This callback function must return the number of bytes actually taken care of.
If that amount differs from the amount passed in to your function, it'll signal
an error to the library. This will cause the transfer to get aborted and the
libcurl function in progress will return
If your header function returns nothing, this will signal success and the transfer will be continued.
A complete HTTP header that is passed to this function can be up to
#CURL_MAX_HTTP_HEADER (100K) bytes.
It's important to note that the callback will be invoked for the headers of all responses received after initiating a request and not just the final response. This includes all responses which occur during authentication negotiation. If you need to operate on only the headers from the final response, you will need to collect headers in the callback yourself and use HTTP status lines, for example, to delimit response boundaries.
When a server sends a chunked encoded transfer, it may contain a trailer. That trailer is identical to an HTTP header and if such a trailer is received it is passed to the application using this callback as well. There are several ways to detect it being a trailer and not an ordinary header: 1) it comes after the response-body. 2) it comes after the final header line (CR LF) 3) a Trailer: header among the regular response-headers mention what header(s) to expect in the trailer.
For non-HTTP protocols like FTP, POP3, IMAP and SMTP this function will get called with the server responses to the commands that libcurl sends.