Skip to content
Snippets Groups Projects
Verified Commit e8647ff3 authored by Alexander Olofsson's avatar Alexander Olofsson
Browse files

Add configurable read timeout

parent b62e14bb
No related branches found
No related tags found
No related merge requests found
Pipeline #3379 failed
...@@ -9,6 +9,7 @@ module Passwordstate ...@@ -9,6 +9,7 @@ module Passwordstate
}.freeze }.freeze
attr_accessor :server_url, :auth_data, :headers, :validate_certificate attr_accessor :server_url, :auth_data, :headers, :validate_certificate
attr_reader :timeout
attr_writer :api_type attr_writer :api_type
def initialize(url, options = {}) def initialize(url, options = {})
...@@ -17,6 +18,7 @@ module Passwordstate ...@@ -17,6 +18,7 @@ module Passwordstate
@headers = DEFAULT_HEADERS @headers = DEFAULT_HEADERS
@auth_data = options.select { |k, _v| %i[apikey username password].include? k } @auth_data = options.select { |k, _v| %i[apikey username password].include? k }
@api_type = options.fetch(:api_type) if options.key? :api_type @api_type = options.fetch(:api_type) if options.key? :api_type
@timeout = options.fetch(:timeout, 0)
end end
def logger def logger
...@@ -27,6 +29,11 @@ module Passwordstate ...@@ -27,6 +29,11 @@ module Passwordstate
@api_type || (auth_data.key?(:apikey) ? :api : :winapi) @api_type || (auth_data.key?(:apikey) ? :api : :winapi)
end end
def timeout=(sec)
@timeout = sec
@http.read_timeout = sec if @http
end
def folders def folders
ResourceList.new self, Passwordstate::Resources::Folder, ResourceList.new self, Passwordstate::Resources::Folder,
only: %i[all search post] only: %i[all search post]
...@@ -115,6 +122,7 @@ module Passwordstate ...@@ -115,6 +122,7 @@ module Passwordstate
@http ||= Net::HTTP.new server_url.host, server_url.port @http ||= Net::HTTP.new server_url.host, server_url.port
return @http if @http.active? return @http if @http.active?
@http.read_timeout = @timeout if @timeout
@http.use_ssl = server_url.scheme == 'https' @http.use_ssl = server_url.scheme == 'https'
@http.verify_mode = validate_certificate ? ::OpenSSL::SSL::VERIFY_NONE : nil @http.verify_mode = validate_certificate ? ::OpenSSL::SSL::VERIFY_NONE : nil
@http.start @http.start
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment