From: Cédric Deltheil Date: Sun, 19 Jan 2014 22:24:03 +0000 (+0100) Subject: HTTP POST: omit Content-Length if data size is unknown X-Git-Tag: upstream/7.37.1~751 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=afd288b28f2087fca1f9ae860a05e77750ef44a7;p=platform%2Fupstream%2Fcurl.git HTTP POST: omit Content-Length if data size is unknown This prevents sending a `Content-Length: -1` header, e.g this ocurred with the following combination: * standard HTTP POST (no chunked encoding), * user-defined read function set, * `CURLOPT_POSTFIELDSIZE(_LARGE)` NOT set. With this fix it now behaves like HTTP PUT. --- diff --git a/lib/http.c b/lib/http.c index 04692af..da03a44 100644 --- a/lib/http.c +++ b/lib/http.c @@ -2408,20 +2408,19 @@ CURLcode Curl_http(struct connectdata *conn, bool *done) data->set.postfieldsize: (data->set.postfields? (curl_off_t)strlen(data->set.postfields):-1); } - if(!data->req.upload_chunky) { - /* We only set Content-Length and allow a custom Content-Length if - we don't upload data chunked, as RFC2616 forbids us to set both - kinds of headers (Transfer-Encoding: chunked and Content-Length) */ - - if(conn->bits.authneg || !Curl_checkheaders(data, "Content-Length:")) { - /* we allow replacing this header if not during auth negotiation, - although it isn't very wise to actually set your own */ - result = Curl_add_bufferf(req_buffer, - "Content-Length: %" CURL_FORMAT_CURL_OFF_T - "\r\n", postsize); - if(result) - return result; - } + + /* We only set Content-Length and allow a custom Content-Length if + we don't upload data chunked, as RFC2616 forbids us to set both + kinds of headers (Transfer-Encoding: chunked and Content-Length) */ + if((postsize != -1) && !data->req.upload_chunky && + !Curl_checkheaders(data, "Content-Length:")) { + /* we allow replacing this header if not during auth negotiation, + although it isn't very wise to actually set your own */ + result = Curl_add_bufferf(req_buffer, + "Content-Length: %" CURL_FORMAT_CURL_OFF_T + "\r\n", postsize); + if(result) + return result; } if(!Curl_checkheaders(data, "Content-Type:")) {