CURLOPT_TRAILERFUNCTION.3 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. .\" generated by cd2nroff 0.1 from CURLOPT_TRAILERFUNCTION.md
  2. .TH CURLOPT_TRAILERFUNCTION 3 "2025-01-17" libcurl
  3. .SH NAME
  4. CURLOPT_TRAILERFUNCTION \- callback for sending trailing headers
  5. .SH SYNOPSIS
  6. .nf
  7. #include <curl.h>
  8. int curl_trailer_callback(struct curl_slist ** list, void *userdata);
  9. CURLcode curl_easy_setopt(CURL *handle, CURLOPT_TRAILERFUNCTION,
  10. curl_trailer_callback *func);
  11. .fi
  12. .SH DESCRIPTION
  13. Pass a pointer to a callback function.
  14. This callback function is called once right before sending the final CR LF in
  15. an HTTP chunked transfer to fill a list of trailing headers to be sent before
  16. finishing the HTTP transfer.
  17. You can set the userdata argument with the \fICURLOPT_TRAILERDATA(3)\fP
  18. option.
  19. The trailing headers included in the linked list must not be CRLF\-terminated,
  20. because libcurl adds the appropriate line termination characters after each
  21. header item.
  22. If you use \fIcurl_slist_append(3)\fP to add trailing headers to the \fIcurl_slist\fP
  23. then libcurl duplicates the strings, and frees the \fIcurl_slist\fP once the
  24. trailers have been sent.
  25. If one of the trailing header fields is not formatted correctly it is ignored
  26. and an info message is emitted.
  27. The return value can either be \fBCURL_TRAILERFUNC_OK\fP or
  28. \fBCURL_TRAILERFUNC_ABORT\fP which would respectively instruct libcurl to
  29. either continue with sending the trailers or to abort the request.
  30. If you set this option to NULL, then the transfer proceeds as usual
  31. without any interruptions.
  32. .SH DEFAULT
  33. NULL
  34. .SH PROTOCOLS
  35. This functionality affects http only
  36. .SH EXAMPLE
  37. .nf
  38. static int trailer_cb(struct curl_slist **tr, void *data)
  39. {
  40. /* libcurl frees the list */
  41. *tr = curl_slist_append(*tr, "My-super-awesome-trailer: trailer-stuff");
  42. return CURL_TRAILERFUNC_OK;
  43. }
  44. int main(void)
  45. {
  46. CURL *curl = curl_easy_init();
  47. if(curl) {
  48. CURLcode res;
  49. /* Set the URL of the request */
  50. curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/");
  51. /* Now set it as a put */
  52. curl_easy_setopt(curl, CURLOPT_UPLOAD, 1L);
  53. /* Assuming we have a function that returns the data to be pushed
  54. Let that function be read_cb */
  55. curl_easy_setopt(curl, CURLOPT_READFUNCTION, trailer_cb);
  56. struct curl_slist *headers = NULL;
  57. headers = curl_slist_append(headers, "Trailer: My-super-awesome-trailer");
  58. res = curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
  59. /* Set the trailers filling callback */
  60. curl_easy_setopt(curl, CURLOPT_TRAILERFUNCTION, trailer_cb);
  61. /* Perform the transfer */
  62. res = curl_easy_perform(curl);
  63. curl_easy_cleanup(curl);
  64. curl_slist_free_all(headers);
  65. }
  66. }
  67. .fi
  68. .SH AVAILABILITY
  69. Added in curl 7.64.0
  70. .SH RETURN VALUE
  71. Returns CURLE_OK.
  72. .SH SEE ALSO
  73. .BR CURLOPT_TRAILERDATA (3),
  74. .BR CURLOPT_WRITEFUNCTION (3)