Debian Codegraph @

deps/curl/docs/libcurl/opts/CURLOPT_TRAILERFUNCTION.3

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