net-http icon indicating copy to clipboard operation
net-http copied to clipboard

idea: global timeout settings

Open jjb opened this issue 1 year ago • 1 comments

faraday allows setting global timeouts

Faraday.default_connection_options = Faraday::ConnectionOptions.new({
  open_timeout: ENV.fetch('NET_HTTP_OPEN_TIMEOUT', 5).to_f,
  timeout: ENV.fetch('NET_HTTP_TIMEOUT', 30).to_f
})

If i set this, then i know all my own code which uses faraday, and gems that i use which use faraday (and don't set their own timeouts, which seems to usually be the case), will have this timeout set.

for net-http, i can do some combination of the bellow:

a) set it one by one for my own code b) ask gem authors to allow this to be configured when it's not c) monkeypatch gems d) do a global monkeypatch of net-http e) use the http-cage gem which has't been updated in 3 years (but maybe doesn't need to be, haven't really checked)

it would be great if net-http allowed a global setting, similar to faraday

i would be happy to submit a PR if folks think it's a good idea

jjb avatar May 06 '24 04:05 jjb

here is the meat of the monkeypatch, applied with this method

    # on Net::HTTP
    def initialize(*)
      super
      self.open_timeout = 
      self.read_timeout = 
      self.write_timeout = 
    end

jjb avatar May 09 '24 23:05 jjb