Fork me on GitHub
#babashka
<
2024-03-17
>
Jacob Emcken11:03:20

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 😢 )

borkdude11:03:54

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?

Jacob Emcken11:03:14

I can't find anything in babashka/http-client setting the content-length, so it is probably the Java code 😞

Jacob Emcken11:03:30

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

borkdude11:03:10

Maybe try constructing the request using only Java interop to see if the culprit is indeed there

Jacob Emcken12:03:56

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 🤷

👍 1
Jacob Emcken12:03:31

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 😅