This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2024-03-17
Channels
It seems the header Content-Length: 0
is being added by babashka/http-client
even though the request doesn't have a body - is that intentional?
(spoiler: I have a Microsoft API endpoint which is picky about it, right now my workaround is to provide an almost empty body (`"{}"`) but then it also wants a content-type 😢 )
Can you make a repro? Maybe search the source where bb http client does this or find out if the underlying Java lib does this?
I can't find anything in babashka/http-client
setting the content-length, so it is probably the Java code 😞
I'll poke a bit more around... and let you know what I find. Just wanted to know if there was some intent behind it first
Maybe try constructing the request using only Java interop to see if the culprit is indeed there
will do
I have confirmed that it is the Java code that sets the content length header.
I have also found that the problem must be something else, since setting content-length: 0
using curl
seems to work just fine on the same API 🤷
apparently, the Microsoft API for SharePoint got confused when using HTTP/2 (which Babashka HTTP client seems to default to).
Enforcing version 1.1 "fixed" my problem.
Using version 2 with curl
does however work 🤷
I guess cURL and the Java classes must be doing something slightly different in HTTP version 2 that trips up the API
I am happy that I don't have to see the following error anymore:
HTTP Error 411. The request must be chunked or have a content length.
Just writing here in case some search engines come by 😅
you can also try this: https://github.com/babashka/http-client?tab=readme-ov-file#logging-and-debug
thanks 👍