From f464535bfdd9a83140d8a13c3fe3d937239d1c2a Mon Sep 17 00:00:00 2001 From: Ayoub Boudhar Date: Thu, 6 Dec 2018 10:18:03 +0100 Subject: 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 --- tests/server/sws.c | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) (limited to 'tests/server') diff --git a/tests/server/sws.c b/tests/server/sws.c index cf3d291d9..87c0204c9 100644 --- a/tests/server/sws.c +++ b/tests/server/sws.c @@ -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 */ } -- cgit v1.2.3