http: prefer chunked encoding over Content-Length: 0

Call http_size() before checking the request for empty body to prefer
Transfer-Encoding: chunked even if Content-Length is 0.

Closes #21706
This commit is contained in:
Josef Cejka 2026-05-20 18:07:16 +02:00 committed by Daniel Stenberg
parent 28341c303d
commit ba600296d2
No known key found for this signature in database
GPG key ID: 5CC908FDB71E12C2
3 changed files with 89 additions and 9 deletions

View file

@ -4172,6 +4172,17 @@ static CURLcode http_on_response(struct Curl_easy *data,
goto out;
}
/* final response without error, prepare to receive the body */
result = http_firstwrite(data);
if(result)
goto out;
/* This is the last response that we get for the current request. Check on
* the body size and determine if the response is complete. */
result = http_size(data);
if(result)
goto out;
/* If we requested a "no body", this is a good time to get
* out and return home.
*/
@ -4185,14 +4196,6 @@ static CURLcode http_on_response(struct Curl_easy *data,
if((k->maxdownload == 0) && (k->httpversion_sent < 20))
k->download_done = TRUE;
/* final response without error, prepare to receive the body */
result = http_firstwrite(data);
if(!result)
/* This is the last response that we get for the current request. Check on
* the body size and determine if the response is complete. */
result = http_size(data);
out:
if(last_hd)
/* if not written yet, write it now */