elixir-tesla / tesla

The flexible HTTP client library for Elixir, with support for middleware and multiple adapters.
MIT License
2.01k stars 348 forks source link

Tesla.Middlware.JSON not encoding? #704

Closed GustavoZiaugra closed 3 months ago

GustavoZiaugra commented 3 months ago

Hi, After the patch to the version that included https://github.com/elixir-tesla/tesla/pull/702 we decided to move from HTTPC to FInch as the adapter and now we are facing a strange issue when sending any requests that includes a content as a JSON.

Usually our clients follow the above struct:

defp middlware do 
    .... (other middlwares)
    Tesla.Middlware.JSON,
     Tesla.Middlware.Logger
    ....
end

All those requests with Finch as adapter and the upper struct for requests that includes JSON body are returning a 400 response from the external services.

Doing a quick look into, looks like Tesla.Middlware.JSON is not encoding the body before send the request as it was made with httpc before. Forcing a manual Jason.encode!(params) was making the request work again.

Is there's some issue with Tesla.Middlware.JSON when using Finch as the adapter? Or there's something missing on our side?

Thanks you in advance, Zig!

Enviroment:

GustavoZiaugra commented 3 months ago

Found the issue:

We were sending a custom header called 'Content-Type' and it was conflicting with the 'content-type' header generated by Tesla.Middleware.JSON...

Sorry about the issue

yordis commented 3 months ago

I was about to reply I am glad you figured it out 💜