CURLOPT_TRAILERFUNCTION.3 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. .\" **************************************************************************
  2. .\" * _ _ ____ _
  3. .\" * Project ___| | | | _ \| |
  4. .\" * / __| | | | |_) | |
  5. .\" * | (__| |_| | _ <| |___
  6. .\" * \___|\___/|_| \_\_____|
  7. .\" *
  8. .\" * Copyright (C) 1998 - 2021, 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 https://curl.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_TRAILERFUNCTION 3 "14 Aug 2018" "libcurl 7.64.0" "curl_easy_setopt options"
  24. .SH NAME
  25. CURLOPT_TRAILERFUNCTION \- callback for sending trailing headers
  26. .SH SYNOPSIS
  27. .nf
  28. #include <curl.h>
  29. int curl_trailer_callback(struct curl_slist ** list, void *userdata);
  30. CURLcode curl_easy_setopt(CURL *handle, CURLOPT_TRAILERFUNCTION,
  31. curl_trailer_callback *func);
  32. .fi
  33. .SH DESCRIPTION
  34. Pass a pointer to a callback function.
  35. This callback function will be called once right before sending the final
  36. CR LF in an HTTP chunked transfer to fill a list of trailing headers to be
  37. sent before finishing the HTTP transfer.
  38. You can set the userdata argument with the CURLOPT_TRAILERDATA option.
  39. The trailing headers included in the linked list must not be CRLF-terminated,
  40. because libcurl will add the appropriate line termination characters after
  41. each header item.
  42. If you use curl_slist_append to add trailing headers to the curl_slist then
  43. libcurl will duplicate the strings, and will free the curl_slist and the
  44. duplicates once the trailers have been sent.
  45. If one of the trailing headers is not formatted correctly
  46. (i.e. HeaderName: headerdata) it will be ignored and an info message
  47. will be emitted.
  48. The return value can either be CURL_TRAILERFUNC_OK or CURL_TRAILERFUNC_ABORT
  49. which would respectively instruct libcurl to either continue with sending the
  50. trailers or to abort the request.
  51. If you set this option to NULL, then the transfer proceeds as usual
  52. without any interruptions.
  53. .SH DEFAULT
  54. NULL
  55. .SH PROTOCOLS
  56. HTTP
  57. .SH EXAMPLE
  58. #include <curl/curl.h>
  59. static int trailer_cb(struct curl_slist **tr, void *data)
  60. {
  61. /* libcurl will free the list */
  62. *tr = curl_slist_append(*tr, "My-super-awesome-trailer: trailer-stuff");
  63. return CURL_TRAILERFUNC_OK;
  64. }
  65. CURL *curl = curl_easy_init();
  66. if(curl) {
  67. /* Set the URL of the request */
  68. curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/");
  69. /* Now set it as a put */
  70. curl_easy_setopt(curl, CURLOPT_PUT, 1L);
  71. /* Assuming we have a function that will return the data to be pushed
  72. Let that function be read_cb */
  73. curl_easy_setopt(curl, CURLOPT_READFUNCTION, read_cb);
  74. struct curl_slist *headers = NULL;
  75. headers = curl_slist_append(headers, "Trailer: My-super-awesome-trailer");
  76. res = curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
  77. /* Set the trailers filling callback */
  78. curl_easy_setopt(curl, CURLOPT_TRAILERFUNCTION, trailer_cb);
  79. /* Perform the request, res will get the return code */
  80. res = curl_easy_perform(curl);
  81. curl_easy_cleanup(curl);
  82. curl_slist_free_all(headers);
  83. }
  84. .SH AVAILABILITY
  85. This option was added in curl 7.64.0 and is present if HTTP support is enabled
  86. .SH RETURN VALUE
  87. Returns CURLE_OK.
  88. .SH "SEE ALSO"
  89. .BR CURLOPT_TRAILERDATA "(3), "