Skip to content

http: prefer chunked encoding over Content-Length: 0#21706

Closed
malyzelenyhnus wants to merge 1 commit into
curl:masterfrom
malyzelenyhnus:chunked-length
Closed

http: prefer chunked encoding over Content-Length: 0#21706
malyzelenyhnus wants to merge 1 commit into
curl:masterfrom
malyzelenyhnus:chunked-length

Conversation

@malyzelenyhnus

Copy link
Copy Markdown
Contributor

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

http_size() sets k->maxdownload to -1 if both headers are present to ignore content-length so it must be called before following code:

if((k->maxdownload == 0) && (k->httpversion_sent < 20))
     k->download_done = TRUE;

Current ordering causes that with Content-Length : 0 is k->download_done set to True preventing remaining chunked data from being read.

@testclutch

Copy link
Copy Markdown

Analysis of PR #21706 at 6cebe13c:

Test 795 failed, which has NOT been flaky recently, so there could be a real issue in this PR. Note that this test has failed in 12 different CI jobs (the link just goes to one of them).

Generated by Testclutch

@vszakats

vszakats commented May 21, 2026

Copy link
Copy Markdown
Member

Please rebase on master to fix the many CI errors. (it's due to a mistake I made)

@dfandrich

dfandrich commented May 21, 2026 via email

Copy link
Copy Markdown
Contributor

@malyzelenyhnus

malyzelenyhnus commented May 22, 2026

Copy link
Copy Markdown
Contributor Author

Is this gated on the use of HTTP/1.1 since chunked encoding isn't supported on earlier versions?

This patch should only fix the conflict between chunked encoding and Content-Length headers - it's broken for the special case when Content-Length is zero. It should not change the current curl behavior in other ways.

And yes, chunked encoding should no be enabled in HTTP/1.0 and it looks like curl does not check the version. But IMO that's different issue.

@icing

icing commented May 22, 2026

Copy link
Copy Markdown
Contributor

Is this gated on the use of HTTP/1.1 since chunked encoding isn't supported on earlier versions?

This patch should only fix the conflict between chunked encoding and Content-Length headers - it's broken for the special case when Content-Length is zero. It should not change the current curl behavior in other ways.

Yes, the patch looks correct. When Transfer-Encoding: chunked is present, a Content-Length: header should be ignored.

And yes, chunked encoding should no be enabled in HTTP/1.0 and it looks like curl does not check the version. But IMO that's different issue.

Well, a HTTP/1.0 response should not carry chunked, so the server is already in error. libcurl could fail the transfer in this case. Maybe worth it, not sure.

@bagder

bagder commented May 27, 2026

Copy link
Copy Markdown
Member

Thanks, can you check the conflict and force-push? Someone else stole the test number you used!

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

bagder commented Jun 1, 2026

Copy link
Copy Markdown
Member

Thanks!

outcast36 pushed a commit to greearb/curl that referenced this pull request Jun 3, 2026
Call http_size() before checking the request for empty body to prefer
Transfer-Encoding: chunked even if Content-Length is 0.

Closes curl#21706
dkarpov1970 pushed a commit to dkarpov1970/curl that referenced this pull request Jun 9, 2026
Call http_size() before checking the request for empty body to prefer
Transfer-Encoding: chunked even if Content-Length is 0.

Closes curl#21706
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Development

Successfully merging this pull request may close these issues.

6 participants