diff --git a/README.md b/README.md index 2d40f27..432be22 100644 --- a/README.md +++ b/README.md @@ -53,6 +53,11 @@ Fcmpush.configure do |config| # config.proxy = { uri: "http://proxy.host:3128", user: nil, password: nil } # explicitly disable using proxy, even ignore environment variables if set # config.proxy = false + + # HTTP connection open and read timeouts (in seconds) are set for all client requests. + # If unset, the default values for Net::HTTP::Persistent are used (currently 60 seconds). + # config.open_timeout = 30 + # config.read_timeout = 15 end ``` diff --git a/lib/fcmpush/client.rb b/lib/fcmpush/client.rb index bece97f..c47568c 100644 --- a/lib/fcmpush/client.rb +++ b/lib/fcmpush/client.rb @@ -26,6 +26,9 @@ def initialize(domain, project_id, configuration, **options) # @server_key = configuration.server_key @connection = Net::HTTP::Persistent.new + @connection.open_timeout = configuration.open_timeout if configuration.open_timeout + @connection.read_timeout = configuration.read_timeout if configuration.read_timeout + if !configuration.proxy # do nothing elsif configuration.proxy == :ENV diff --git a/lib/fcmpush/configuration.rb b/lib/fcmpush/configuration.rb index 8836bcb..7a97116 100644 --- a/lib/fcmpush/configuration.rb +++ b/lib/fcmpush/configuration.rb @@ -1,6 +1,6 @@ module Fcmpush class Configuration - attr_accessor :scope, :json_key_io, :server_key, :proxy + attr_accessor :scope, :json_key_io, :server_key, :proxy, :open_timeout, :read_timeout def initialize @scope = ['https://www.googleapis.com/auth/firebase.messaging'] @@ -26,6 +26,10 @@ def initialize # cf. https://github.com/miyataka/fcmpush/pull/39#issuecomment-1722533622 # proxy @proxy = :ENV + + # connection timeouts + @open_timeout = nil + @read_timeout = nil end end end