CURLOPT_HEADERFUNCTION.3 4.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. .\" **************************************************************************
  2. .\" * _ _ ____ _
  3. .\" * Project ___| | | | _ \| |
  4. .\" * / __| | | | |_) | |
  5. .\" * | (__| |_| | _ <| |___
  6. .\" * \___|\___/|_| \_\_____|
  7. .\" *
  8. .\" * Copyright (C) 1998 - 2014, Daniel Stenberg, <daniel@haxx.se>, et al.
  9. .\" *
  10. .\" * This software is licensed as described in the file COPYING, which
  11. .\" * you should have received as part of this distribution. The terms
  12. .\" * are also available at http://curl.haxx.se/docs/copyright.html.
  13. .\" *
  14. .\" * You may opt to use, copy, modify, merge, publish, distribute and/or sell
  15. .\" * copies of the Software, and permit persons to whom the Software is
  16. .\" * furnished to do so, under the terms of the COPYING file.
  17. .\" *
  18. .\" * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
  19. .\" * KIND, either express or implied.
  20. .\" *
  21. .\" **************************************************************************
  22. .\"
  23. .TH CURLOPT_HEADERFUNCTION 3 "17 Jun 2014" "libcurl 7.37.0" "curl_easy_setopt options"
  24. .SH NAME
  25. CURLOPT_HEADERFUNCTION \- callback that receives header data
  26. .SH SYNOPSIS
  27. #include <curl/curl.h>
  28. size_t header_callback(char *buffer,
  29. size_t size,
  30. size_t nitems,
  31. void *userdata);
  32. CURLcode curl_easy_setopt(CURL *handle, CURLOPT_HEADERFUNCTION, header_callback);
  33. .SH DESCRIPTION
  34. Pass a pointer to your callback function, which should match the prototype
  35. shown above.
  36. This function gets called by libcurl as soon as it has received header
  37. data. The header callback will be called once for each header and only
  38. complete header lines are passed on to the callback. Parsing headers is very
  39. easy using this. The size of the data pointed to by \fIptr\fP is \fIsize\fP
  40. multiplied with \fInmemb\fP. Do not assume that the header line is zero
  41. terminated! The pointer named \fIuserdata\fP is the one you set with the
  42. \fICURLOPT_HEADERDATA(3)\fP option. This callback function must return the
  43. number of bytes actually taken care of. If that amount differs from the amount
  44. passed in to your function, it'll signal an error to the library. This will
  45. cause the transfer to get aborted and the libcurl function in progress will
  46. return \fICURL_WRITE_ERROR\fP.
  47. A complete HTTP header that is passed to this function can be up to
  48. \fICURL_MAX_HTTP_HEADER\fP (100K) bytes.
  49. If this option is not set, or if it is set to NULL, but
  50. \fICURLOPT_HEADERDATA(3)\fP is set to anything but NULL, the function used to
  51. accept response data will be used instead. That is, it will be the function
  52. specified with \fICURLOPT_WRITEFUNCTION(3)\fP, or if it is not specified or
  53. NULL - the default, stream-writing function.
  54. It's important to note that the callback will be invoked for the headers of
  55. all responses received after initiating a request and not just the final
  56. response. This includes all responses which occur during authentication
  57. negotiation. If you need to operate on only the headers from the final
  58. response, you will need to collect headers in the callback yourself and use
  59. HTTP status lines, for example, to delimit response boundaries.
  60. When a server sends a chunked encoded transfer, it may contain a trailer. That
  61. trailer is identical to a HTTP header and if such a trailer is received it is
  62. passed to the application using this callback as well. There are several ways
  63. to detect it being a trailer and not an ordinary header: 1) it comes after the
  64. response-body. 2) it comes after the final header line (CR LF) 3) a Trailer:
  65. header among the regular response-headers mention what header(s) to expect in
  66. the trailer.
  67. For non-HTTP protocols like FTP, POP3, IMAP and SMTP this function will get
  68. called with the server responses to the commands that libcurl sends.
  69. .SH DEFAULT
  70. Nothing.
  71. .SH PROTOCOLS
  72. Used for all protocols with headers or meta-data concept: HTTP, FTP, POP3,
  73. IMAP, SMTP and more.
  74. .SH EXAMPLE
  75. TODO
  76. .SH AVAILABILITY
  77. Always
  78. .SH RETURN VALUE
  79. Returns CURLE_OK
  80. .SH "SEE ALSO"
  81. .BR CURLOPT_HEADERDATA "(3), " CURLOPT_WRITEFUNCTION "(3), "