Globally Configure Faraday User-Agent

Viewed 3858

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.

3 Answers

For anyone specifically trying to set default timeout options like we were, this worked for us in a modern Faraday implementation:

Faraday.default_connection_options = Faraday::ConnectionOptions.new({timeout: 5, open_timeout: 5})

You could also set any other request options inside that hash.

This is what worked for me in the faraday version 1.1.0.

Faraday.default_connection_options.headers = { "User-Agent" => 'Mozilla/5.0' }
Related