rubycasfaraday

Globally Configure Faraday User-Agent


I have inherited a Ruby project forked from CASinoApp, which depends on CASino, which uses Faraday for HTTP requests. I really do not want to fork CASino to modify how it invokes Faraday.post.

Is there a way to configure Faraday globally to set it's User-Agent for any-and-all requests that follow? Specifically, I cannot run Faraday's constructor to get a connection and configure it - because CASino would not then use my configured connection for it's requests. I need to somehow mutate Faraday's internal "default" configuration.


Solution

  • In modern versions of Faraday, you should be able to use Faraday.default_connection_options. In our case, we were stuck using 0.9.2 and had to actually configure a connection object and set Faraday.default_connection for reasons addressed in 0.12.2.

    Faraday.default_connection = Faraday.new(options = {:headers=>{:user_agent=>"My Custom UA Here"}})