Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Globally Configure Faraday User-Agent

Tags:

ruby

cas

faraday

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.

like image 883
Chris Trahey Avatar asked Nov 02 '25 04:11

Chris Trahey


1 Answers

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"}})
like image 82
Chris Trahey Avatar answered Nov 04 '25 20:11

Chris Trahey