lostisland/faraday

User-Agent is set to Ruby when setting an empty hash as headers

Closed this issue · 3 comments

Basic Info

  • Faraday Version: 1.4.1
  • Ruby Version: 2.6.6

Issue description

So, I noticed some curious behavior on the User-Agent request header field sent when doing POST requests. If I provide an empty hash as header Faraday sets the User-Agent value to Ruby for some reason. Otherwise it's just Faraday v1.4.1 like expected.

Steps to reproduce

Start a ngrok server locally with (or any server which lets you see requests coming): ngrok http 8080

and call the endpoint in irb like this:

client = Faraday.new(url: ngrok_url)
client.post do |req|
     req.headers = {}
end

the User-Agent request header should come as Ruby. Is that behavior expected?

Guessing: does it come from net/http in the standard library?

Yes, seems like you're right. net/http sets that value when no agent is provided. I just wonder if this behavior is desidered in Faraday.

Anyway, thanks @olleolleolle!

I agree as well that Faraday is delegating to the adapters the actual execution of the HTTP call, passing the necessary configuration to them.
It doesn't seem like Net::HTTP allows a configuration to disable this behaviour, so this puts the whole thing outside of Faraday's hands in my opinion.

Appreciate this is not ideal, but you may consider using another adapter that doesn't have this issue if this is really important?
It's pretty easy to switch adapters