CURLOPT_TRAILERFUNCTION.3 3.8 KB

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