1CURLOPT_TRAILERFUNCTION(3) curl_easy_setopt options CURLOPT_TRAILERFUNCTION(3)
2
3
4
6 CURLOPT_TRAILERFUNCTION - callback for sending trailing headers
7
9 #include <curl.h>
10
11 int curl_trailer_callback(struct curl_slist ** list, void *userdata);
12
13 CURLcode curl_easy_setopt(CURL *handle, CURLOPT_TRAILERFUNCTION,
14 curl_trailer_callback *func);
15
17 Pass a pointer to a callback function.
18
19 This callback function will be called once right before sending the fi‐
20 nal CR LF in an HTTP chunked transfer to fill a list of trailing head‐
21 ers to be sent before finishing the HTTP transfer.
22
23 You can set the userdata argument with the CURLOPT_TRAILERDATA option.
24
25 The trailing headers included in the linked list must not be CRLF-ter‐
26 minated, because libcurl will add the appropriate line termination
27 characters after each header item.
28
29 If you use curl_slist_append to add trailing headers to the curl_slist
30 then libcurl will duplicate the strings, and will free the curl_slist
31 and the duplicates once the trailers have been sent.
32
33 If one of the trailing headers is not formatted correctly (i.e. Header‐
34 Name: headerdata) it will be ignored and an info message will be emit‐
35 ted.
36
37 The return value can either be CURL_TRAILERFUNC_OK or CURL_TRAILER‐
38 FUNC_ABORT which would respectively instruct libcurl to either continue
39 with sending the trailers or to abort the request.
40
41 If you set this option to NULL, then the transfer proceeds as usual
42 without any interruptions.
43
45 NULL
46
48 HTTP
49
51 #include <curl/curl.h>
52
53 static int trailer_cb(struct curl_slist **tr, void *data) {
54 /* libcurl will free the list */
55 *tr = curl_slist_append(*tr, "My-super-awesome-trailer: trailer-
56 stuff");
57 return CURL_TRAILERFUNC_OK; }
58
59 CURL *curl = curl_easy_init(); if(curl) {
60 /* Set the URL of the request */
61 curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/");
62 /* Now set it as a put */
63 curl_easy_setopt(curl, CURLOPT_PUT, 1L);
64
65 /* Assuming we have a function that will return the data to be pushed
66 Let that function be read_cb */
67 curl_easy_setopt(curl, CURLOPT_READFUNCTION, read_cb);
68
69 struct curl_slist *headers = NULL;
70 headers = curl_slist_append(headers, "Trailer: My-super-awesome-
71 trailer");
72 res = curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
73
74 /* Set the trailers filling callback */
75 curl_easy_setopt(curl, CURLOPT_TRAILERFUNCTION, trailer_cb);
76
77 /* Perform the request, res will get the return code */
78 res = curl_easy_perform(curl);
79
80 curl_easy_cleanup(curl);
81
82 curl_slist_free_all(headers); }
83
85 This option was added in curl 7.64.0 and is present if HTTP support is
86 enabled
87
89 Returns CURLE_OK.
90
92 CURLOPT_TRAILERDATA(3),
93
94
95
96libcurl 7.85.0 May 17, 2022 CURLOPT_TRAILERFUNCTION(3)