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