http: Implement trailing headers for chunked transfers

This adds the CURLOPT_TRAILERDATA and CURLOPT_TRAILERFUNCTION
options that allow a callback based approach to sending trailing headers
with chunked transfers.

The test server (sws) was updated to take into account the detection of the
end of transfer in the case of trailing headers presence.

Test 1591 checks that trailing headers can be sent using libcurl.

Closes #3350
This commit is contained in:
Ayoub Boudhar 2018-12-06 10:18:03 +01:00 committed by Daniel Stenberg
parent 4531b299cc
commit f464535bfd
No known key found for this signature in database
GPG key ID: 5CC908FDB71E12C2
17 changed files with 618 additions and 22 deletions

View file

@ -253,6 +253,9 @@ SIG_ATOMIC_T got_exit_signal = 0;
static volatile int exit_signal = 0;
/* work around for handling trailing headers */
static int already_recv_zeroed_chunk = FALSE;
/* signal handler that will be triggered to indicate that the program
should finish its execution in a controlled manner as soon as possible.
The first time this is called it will set got_exit_signal to one and
@ -755,10 +758,27 @@ static int ProcessRequest(struct httprequest *req)
chunked = TRUE;
}
if(chunked) {
if(strstr(req->reqbuf, "\r\n0\r\n\r\n"))
if(strstr(req->reqbuf, "\r\n0\r\n\r\n")) {
/* end of chunks reached */
return 1; /* done */
}
else if(strstr(req->reqbuf, "\r\n0\r\n")) {
char *last_crlf_char = strstr(req->reqbuf, "\r\n\r\n");
while(TRUE) {
if(!strstr(last_crlf_char + 4, "\r\n\r\n"))
break;
last_crlf_char = strstr(last_crlf_char + 4, "\r\n\r\n");
}
if(last_crlf_char &&
last_crlf_char > strstr(req->reqbuf, "\r\n0\r\n"))
return 1;
already_recv_zeroed_chunk = TRUE;
return 0;
}
else if(already_recv_zeroed_chunk && strstr(req->reqbuf, "\r\n\r\n"))
return 1;
else
return 0; /* not done */
}