Skip to content

Send Content-Length: 0 for empty POST/PUT/PATCH bodies - #925

Merged
benoitc merged 1 commit into
masterfrom
fix/content-length-zero-empty-body
Aug 11, 2026
Merged

Send Content-Length: 0 for empty POST/PUT/PATCH bodies#925
benoitc merged 1 commit into
masterfrom
fix/content-length-zero-empty-body

Conversation

@benoitc

@benoitc benoitc commented Aug 11, 2026

Copy link
Copy Markdown
Owner

Supersedes #917 with curl's convention.

Today hackney sends no Content-Length for an empty body. curl sends an explicit Content-Length: 0 for body-bearing methods (POST/PUT/PATCH) even when the body is empty, and omits it for bodyless methods (GET/HEAD/DELETE). This matches that: POST/PUT/PATCH with an empty body get Content-Length: 0 (unless the caller already set one); GET/HEAD/DELETE are unchanged.

Fixes servers that require the header on a 0-length body, e.g. the AWS case reported in aws-beam/aws-elixir#238 (surfaced in #917).

Note vs #917: it stored the integer 0 (breaks the hackney_headers:store binary-value contract, which is why its dialyzer job failed) and added the header for every method. This uses <<"0">> and scopes it to body-bearing methods.

Like curl, add an explicit Content-Length: 0 when a body-bearing method
(POST/PUT/PATCH) is sent with an empty body, unless the caller already set
one. Bodyless methods (GET/HEAD/DELETE) stay without it. Fixes servers such
as AWS that require Content-Length even for a 0-length body.
@benoitc
benoitc merged commit 0516b9a into master Aug 11, 2026
6 checks passed
@benoitc benoitc mentioned this pull request Aug 11, 2026
benoitc added a commit that referenced this pull request Aug 11, 2026
Bundles the fixes merged since 4.7.2 (#914/#915, #918/#919, #920, #921,
#922, #924) and the curl-style Content-Length change (#917/#925). Bumps
dependencies to their latest releases: quic 1.8.0, webtransport 0.4.4,
mimerl 1.5.0, cowboy 2.18.0 (test).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant