CURLOPT_TRAILERFUNCTION.3 3.7 KB

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