1CURLOPT_TRAILERFUNCTION(3) curl_easy_setopt options CURLOPT_TRAILERFUNCTION(3)
2
3
4

NAME

6       CURLOPT_TRAILERFUNCTION - Set callback for sending trailing headers
7

SYNOPSIS

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

DESCRIPTION

17       Pass a pointer to a callback function.
18
19       This callback function will be called once  right  before  sending  the
20       final  CR  LF  in  an  HTTP chunked transfer to fill a list of trailing
21       headers 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

DEFAULT

45       NULL
46

PROTOCOLS

48       HTTP
49

EXAMPLE

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, "http://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-awsome-
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

AVAILABILITY

85       This  option was added in curl 7.64.0 and is present if HTTP support is
86       enabled
87

SEE ALSO

89       CURLOPT_TRAILERDATA(3),
90
91
92
93libcurl 7.71.1                 October 31, 2019     CURLOPT_TRAILERFUNCTION(3)
Impressum