1*6236dae4SAndroid Build Coastguard Worker--- 2*6236dae4SAndroid Build Coastguard Workerc: Copyright (C) Daniel Stenberg, <[email protected]>, et al. 3*6236dae4SAndroid Build Coastguard WorkerSPDX-License-Identifier: curl 4*6236dae4SAndroid Build Coastguard WorkerTitle: CURLOPT_TRAILERFUNCTION 5*6236dae4SAndroid Build Coastguard WorkerSection: 3 6*6236dae4SAndroid Build Coastguard WorkerSource: libcurl 7*6236dae4SAndroid Build Coastguard WorkerSee-also: 8*6236dae4SAndroid Build Coastguard Worker - CURLOPT_TRAILERDATA (3) 9*6236dae4SAndroid Build Coastguard Worker - CURLOPT_WRITEFUNCTION (3) 10*6236dae4SAndroid Build Coastguard WorkerProtocol: 11*6236dae4SAndroid Build Coastguard Worker - HTTP 12*6236dae4SAndroid Build Coastguard WorkerAdded-in: 7.64.0 13*6236dae4SAndroid Build Coastguard Worker--- 14*6236dae4SAndroid Build Coastguard Worker 15*6236dae4SAndroid Build Coastguard Worker# NAME 16*6236dae4SAndroid Build Coastguard Worker 17*6236dae4SAndroid Build Coastguard WorkerCURLOPT_TRAILERFUNCTION - callback for sending trailing headers 18*6236dae4SAndroid Build Coastguard Worker 19*6236dae4SAndroid Build Coastguard Worker# SYNOPSIS 20*6236dae4SAndroid Build Coastguard Worker 21*6236dae4SAndroid Build Coastguard Worker~~~c 22*6236dae4SAndroid Build Coastguard Worker#include <curl.h> 23*6236dae4SAndroid Build Coastguard Worker 24*6236dae4SAndroid Build Coastguard Workerint curl_trailer_callback(struct curl_slist ** list, void *userdata); 25*6236dae4SAndroid Build Coastguard Worker 26*6236dae4SAndroid Build Coastguard WorkerCURLcode curl_easy_setopt(CURL *handle, CURLOPT_TRAILERFUNCTION, 27*6236dae4SAndroid Build Coastguard Worker curl_trailer_callback *func); 28*6236dae4SAndroid Build Coastguard Worker~~~ 29*6236dae4SAndroid Build Coastguard Worker 30*6236dae4SAndroid Build Coastguard Worker# DESCRIPTION 31*6236dae4SAndroid Build Coastguard Worker 32*6236dae4SAndroid Build Coastguard WorkerPass a pointer to a callback function. 33*6236dae4SAndroid Build Coastguard Worker 34*6236dae4SAndroid Build Coastguard WorkerThis callback function is called once right before sending the final CR LF in 35*6236dae4SAndroid Build Coastguard Workeran HTTP chunked transfer to fill a list of trailing headers to be sent before 36*6236dae4SAndroid Build Coastguard Workerfinishing the HTTP transfer. 37*6236dae4SAndroid Build Coastguard Worker 38*6236dae4SAndroid Build Coastguard WorkerYou can set the userdata argument with the CURLOPT_TRAILERDATA(3) 39*6236dae4SAndroid Build Coastguard Workeroption. 40*6236dae4SAndroid Build Coastguard Worker 41*6236dae4SAndroid Build Coastguard WorkerThe trailing headers included in the linked list must not be CRLF-terminated, 42*6236dae4SAndroid Build Coastguard Workerbecause libcurl adds the appropriate line termination characters after each 43*6236dae4SAndroid Build Coastguard Workerheader item. 44*6236dae4SAndroid Build Coastguard Worker 45*6236dae4SAndroid Build Coastguard WorkerIf you use curl_slist_append(3) to add trailing headers to the *curl_slist* 46*6236dae4SAndroid Build Coastguard Workerthen libcurl duplicates the strings, and frees the *curl_slist* once the 47*6236dae4SAndroid Build Coastguard Workertrailers have been sent. 48*6236dae4SAndroid Build Coastguard Worker 49*6236dae4SAndroid Build Coastguard WorkerIf one of the trailing header fields is not formatted correctly it is ignored 50*6236dae4SAndroid Build Coastguard Workerand an info message is emitted. 51*6236dae4SAndroid Build Coastguard Worker 52*6236dae4SAndroid Build Coastguard WorkerThe return value can either be **CURL_TRAILERFUNC_OK** or 53*6236dae4SAndroid Build Coastguard Worker**CURL_TRAILERFUNC_ABORT** which would respectively instruct libcurl to 54*6236dae4SAndroid Build Coastguard Workereither continue with sending the trailers or to abort the request. 55*6236dae4SAndroid Build Coastguard Worker 56*6236dae4SAndroid Build Coastguard WorkerIf you set this option to NULL, then the transfer proceeds as usual 57*6236dae4SAndroid Build Coastguard Workerwithout any interruptions. 58*6236dae4SAndroid Build Coastguard Worker 59*6236dae4SAndroid Build Coastguard Worker# DEFAULT 60*6236dae4SAndroid Build Coastguard Worker 61*6236dae4SAndroid Build Coastguard WorkerNULL 62*6236dae4SAndroid Build Coastguard Worker 63*6236dae4SAndroid Build Coastguard Worker# %PROTOCOLS% 64*6236dae4SAndroid Build Coastguard Worker 65*6236dae4SAndroid Build Coastguard Worker# EXAMPLE 66*6236dae4SAndroid Build Coastguard Worker~~~c 67*6236dae4SAndroid Build Coastguard Workerstatic int trailer_cb(struct curl_slist **tr, void *data) 68*6236dae4SAndroid Build Coastguard Worker{ 69*6236dae4SAndroid Build Coastguard Worker /* libcurl frees the list */ 70*6236dae4SAndroid Build Coastguard Worker *tr = curl_slist_append(*tr, "My-super-awesome-trailer: trailer-stuff"); 71*6236dae4SAndroid Build Coastguard Worker return CURL_TRAILERFUNC_OK; 72*6236dae4SAndroid Build Coastguard Worker} 73*6236dae4SAndroid Build Coastguard Worker 74*6236dae4SAndroid Build Coastguard Workerint main(void) 75*6236dae4SAndroid Build Coastguard Worker{ 76*6236dae4SAndroid Build Coastguard Worker CURL *curl = curl_easy_init(); 77*6236dae4SAndroid Build Coastguard Worker if(curl) { 78*6236dae4SAndroid Build Coastguard Worker CURLcode res; 79*6236dae4SAndroid Build Coastguard Worker 80*6236dae4SAndroid Build Coastguard Worker /* Set the URL of the request */ 81*6236dae4SAndroid Build Coastguard Worker curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/"); 82*6236dae4SAndroid Build Coastguard Worker /* Now set it as a put */ 83*6236dae4SAndroid Build Coastguard Worker curl_easy_setopt(curl, CURLOPT_UPLOAD, 1L); 84*6236dae4SAndroid Build Coastguard Worker 85*6236dae4SAndroid Build Coastguard Worker /* Assuming we have a function that returns the data to be pushed 86*6236dae4SAndroid Build Coastguard Worker Let that function be read_cb */ 87*6236dae4SAndroid Build Coastguard Worker curl_easy_setopt(curl, CURLOPT_READFUNCTION, trailer_cb); 88*6236dae4SAndroid Build Coastguard Worker 89*6236dae4SAndroid Build Coastguard Worker struct curl_slist *headers = NULL; 90*6236dae4SAndroid Build Coastguard Worker headers = curl_slist_append(headers, "Trailer: My-super-awesome-trailer"); 91*6236dae4SAndroid Build Coastguard Worker res = curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers); 92*6236dae4SAndroid Build Coastguard Worker 93*6236dae4SAndroid Build Coastguard Worker /* Set the trailers filling callback */ 94*6236dae4SAndroid Build Coastguard Worker curl_easy_setopt(curl, CURLOPT_TRAILERFUNCTION, trailer_cb); 95*6236dae4SAndroid Build Coastguard Worker 96*6236dae4SAndroid Build Coastguard Worker /* Perform the transfer */ 97*6236dae4SAndroid Build Coastguard Worker res = curl_easy_perform(curl); 98*6236dae4SAndroid Build Coastguard Worker 99*6236dae4SAndroid Build Coastguard Worker curl_easy_cleanup(curl); 100*6236dae4SAndroid Build Coastguard Worker 101*6236dae4SAndroid Build Coastguard Worker curl_slist_free_all(headers); 102*6236dae4SAndroid Build Coastguard Worker } 103*6236dae4SAndroid Build Coastguard Worker} 104*6236dae4SAndroid Build Coastguard Worker~~~ 105*6236dae4SAndroid Build Coastguard Worker 106*6236dae4SAndroid Build Coastguard Worker# %AVAILABILITY% 107*6236dae4SAndroid Build Coastguard Worker 108*6236dae4SAndroid Build Coastguard Worker# RETURN VALUE 109*6236dae4SAndroid Build Coastguard Worker 110*6236dae4SAndroid Build Coastguard WorkerReturns CURLE_OK. 111