elixir-mint / mint

Functional HTTP client for Elixir with support for HTTP/1 and HTTP/2 🌱
Apache License 2.0
1.36k stars 112 forks source link

http1: add Content-Length header field even when the payload is empty #342

Closed ryochin closed 2 years ago

ryochin commented 2 years ago

Some servers return the 411 HTTP status code when the Content-Length header field is missing on POST requests. I notice that happens at the first request of Digest Auth using Tesla, for example.

ericmj commented 2 years ago

If you want to send an empty body (and therefor set content-length: 0) you should set the body as "" instead of nil.

If you instead set the body as nil then no body will be sent and a content-length: 0 would be incorrect in that case.

whatyouhide commented 2 years ago

Agreed with @ericmj. Thanks anyways @ryochin! 💟