cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: [PATCH] Addition of trailer headers in HTTP requests generated by libcurl

From: Dan Fandrich <dan_at_coneharvesters.com>
Date: Thu, 24 Jan 2013 14:55:58 +0100

On Thu, Jan 24, 2013 at 12:03:51PM +0200, Chrysovaladis Datsios wrote:
> **** curl_easy_setopt() option: CURLOPT_HTTPTRAILERHEADER

Is this option even necessary any more? The CURLOPT_HTTPHEADER option can be
used to set a Trailer: header and the new callback function is then used to
send the actual trailer values.

> Pass a pointer to a linked list of HTTP trailer headers to pass at the
> end of the HTTP request. The HTTP request should be using chunked

Rather, it *must* be using chunked encoding.

> Transfer-Encoding. The linked list of HTTP trailer headers should be a
> fully valid list of struct curl_slist structs properly filled in. Use
> curl_slist_append(3) to create the list and curl_slist_free_all(3) to
> clean up an entire list.
> The option is set before the curl_easy_perfom(1). The linked list of
> HTTP trailer headers contains the initial values of those headers. The
> initial values are not the values that will be sent finally at the end
> of the transfer. The final values of the HTTP trailer headers can be
> known or calculated after the transfer has been performed. For this, a
> new callback function assigned in option CURLOPT_HTTPTRAILERFUNCTION
> has to be defined and it will be called at the end of the transfer.
>
> **** curl_easy_setopt() option: CURLOPT_HTTPTRAILERFUNCTION
>
> Pass a pointer to a function that matches the following prototype: int
> function(struct curl_slist *trailer_headers); This function gets

At the very least, the callback needs to pass in the easy handle
corresponding to the transfer.

> called by libcurl when it is to send the last chunk of (zero
> payload)data to the peer. Chunked transfer-encoding it is assumed. The
> pointer to the trailer_headers points to the linked list of trailer
> headers whose values are to take their final values. The new function
> curl_slist_replace(3) can be called from inside the callback function
> to alter the initial values to the real ones.
>
> **** new function: curl_slist_replace - replace an old string in an
> slist with a new string
> struct curl_slist *curl_slist_replace(struct curl_slist *list, const
> char *old_data, const char *new_data);
>
> Function curl_slist_replace(3) replaces an old string in the linked
> list with an new string. It returns the the address of the first
> record in the list. If no list exists NULL is returned.

If CURLOPT_HTTPTRAILERHEADER is eliminated, then curl_slist_replace no
longer serves a useful function. Unnecessary complexity removed, ×2!

> diff -ur curl_orig/lib/transfer.c curl_new/lib/transfer.c
> --- curl_orig/lib/transfer.c 2012-11-13 23:02:16.000000000 +0200
> +++ curl_new/lib/transfer.c 2013-01-24 11:43:56.053131238 +0200
> @@ -929,6 +929,41 @@
> that instead of reading more data */
> }
>
> + /* The last chunk has zero size of data i.e. 0\r\n
> + * If this is the last chunk and trailer headers do exist*/
> + if(k->upload_chunky == true && data->req.upload_present == 5 &&
> + !strncmp(data->req.upload_fromhere, "0\r\n", 3) &&
> + conn->data->set.trailer_headers ) {

I don't see how this has changed. It will trigger in some cases when the
payload happens to match "0\r\n".

>>> Dan
-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette: http://curl.haxx.se/mail/etiquette.html
Received on 2013-01-24