From 9d191a6a40c2e90153d4b60cbc78fa34837c07ee Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Mon, 11 Apr 2011 16:30:14 +0200 Subject: TE: do the Connection: header When TE: is inserted in the request, we must add a "Connection: TE" as well to be HTTP 1.1 compliant. If a custom Connection: header is passed in, we must use that and only append TE to it. Test case 1125 verifies TE: + custom Connection:. --- lib/http.c | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) (limited to 'lib') diff --git a/lib/http.c b/lib/http.c index c442eebab..8d3a085d0 100644 --- a/lib/http.c +++ b/lib/http.c @@ -1533,6 +1533,11 @@ CURLcode Curl_add_custom_headers(struct connectdata *conn, we will force length zero then */ checkprefix("Content-Length", headers->data)) ; + else if(conn->allocptr.te && + /* when asking for Transfer-Encoding, don't pass on a custom + Connection: */ + checkprefix("Connection", headers->data)) + ; else { CURLcode result = Curl_add_bufferf(req_buffer, "%s\r\n", headers->data); @@ -1728,14 +1733,21 @@ CURLcode Curl_http(struct connectdata *conn, bool *done) return CURLE_OUT_OF_MEMORY; } -#if 0 - if(!Curl_checkheaders(data, "TE:")) { + if(Curl_checkheaders(data, "TE:")) { + /* When we insert a TE: header in the request, we must also insert TE in a + Connection: header, so we need to merge the custom provided Connection: + header and prevent the original to get sent */ + char *cptr = Curl_checkheaders(data, "Connection:"); + Curl_safefree(conn->allocptr.te); - conn->allocptr.te = aprintf("TE: %s\r\n", "gzip"); + + /* Create the (updated) Connection: header */ + conn->allocptr.te = cptr? aprintf("%s, TE\r\n", cptr): + strdup("Connection: TE\r\n"); + if(!conn->allocptr.te) return CURLE_OUT_OF_MEMORY; } -#endif ptr = Curl_checkheaders(data, "Transfer-Encoding:"); if(ptr) { -- cgit v1.2.3