Ok,

seems that the Content-Type is added automatically by libcurl when performing a POST request, unless it detects an already present hdr in the headers params.

Seems that inverting the order of headers, so building the string with "Content-Type: application/json\r\nAuthorization: Bearer sometoken" seems to work, probably because libcurl detects the header and does not add it's own.

But this is something "magic", not documented and prone to breakage, since for libcurl headers should be a linked list of strings.

What do you suggest to properly handle that? Use scripting? Propose a patch to split the headers string into a libcurl linked list?

br,
Mat

On Tue, Sep 12, 2023 at 5:53 PM Matteo Brancaleoni <mbrancaleoni@gmail.com> wrote:
Hello all :)

I'm struggling to add two headers to an http client request, but cannot find a proper way to do it.

The headers are Authorization and Content-Type.

The first try is with http_client module, beside undocumented, is possible to add multiple headers separating them with "\r\n". What I see is the correct Authorization header, and two Content-Type headers, one with my content type the other with x-www-form-urlencoded, which no one sets ?

Second try is with http_async_client which supports multiple headers, but since I'm calling it from an xhttp event route, there's no transaction and request cannot be suspended, so I cannot get results before sending out xhttp response...

Any hint?

br, 
Mat