From aaace4e2b33234c914e215105d530777939a264f Mon Sep 17 00:00:00 2001
From: Alexander Olofsson <alexander.olofsson@liu.se>
Date: Thu, 27 Apr 2023 14:36:44 +0200
Subject: [PATCH] Allow setting an open timeout for client

---
 lib/passwordstate/client.rb | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/lib/passwordstate/client.rb b/lib/passwordstate/client.rb
index e43576d..2fe9b2c 100644
--- a/lib/passwordstate/client.rb
+++ b/lib/passwordstate/client.rb
@@ -11,7 +11,7 @@ module Passwordstate
     }.freeze
 
     attr_accessor :server_url, :auth_data, :headers, :validate_certificate
-    attr_reader :timeout
+    attr_reader :open_timeout, :timeout
     attr_writer :api_type
 
     def initialize(url, options = {})
@@ -20,6 +20,7 @@ module Passwordstate
       @headers = DEFAULT_HEADERS
       @auth_data = options.select { |k, _v| %i[apikey username password].include? k }
       @api_type = options.fetch(:api_type) if options.key? :api_type
+      @open_timeout = options.fetch(:open_timeout, 5)
       @timeout = options.fetch(:timeout, 15)
     end
 
@@ -155,6 +156,7 @@ module Passwordstate
       @http ||= Net::HTTP.new server_url.host, server_url.port
       return @http if @http.active?
 
+      @http.open_timeout = @open_timeout if @open_timeout
       @http.read_timeout = @timeout if @timeout
       @http.use_ssl = server_url.scheme == 'https'
       @http.verify_mode = validate_certificate ? ::OpenSSL::SSL::VERIFY_NONE : nil
-- 
GitLab