Skip to content

Is there a way to remove Faraday's User-Agent header as a default option for all connections? #1248

@dmytro-savochkin

Description

@dmytro-savochkin

Basic Info

  • Faraday Version: 1.3.0
  • Ruby Version: 2.7.2

Issue description

Is there a way to prevent Faraday from sending its User-Agent header (Faraday v1.3.0)? I need it because one of the external servers we are dependent upon has banned it (#1247 (comment)).
Well, I know how to rewrite this header with something else per connection. Also I found how to rewrite it with something else as a default but only when there are no headers added when creating a connection (the new headers overwrite the default ones):

Faraday.default_connection_options = { headers: { user_agent: 'Something 1.2.3' } }
headers = { 'CustomHeader' => 'CustomValue' }
connection = Faraday.new('https://www.google.com', headers: headers) do |f|
  f.response :logger, nil, { headers: true }
end
connection.get

I, [2021-03-15T13:41:49.910701 #7925]  INFO -- request: GET https://www.google.com/
I, [2021-03-15T13:41:49.910993 #7925]  INFO -- request: CustomHeader: "CustomValue" User-Agent: "Faraday v1.3.0"

But I cannot find a way as how to remove that header completely (except for monkey-patching of course). Is there one?

Thank you!

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions