diff --git a/lib/ruby_http_client.rb b/lib/ruby_http_client.rb index d0fff4d..495f498 100644 --- a/lib/ruby_http_client.rb +++ b/lib/ruby_http_client.rb @@ -227,7 +227,9 @@ def make_request(http, request) def build_http(host, port) params = [host, port] params += @proxy_options.values_at(:host, :port, :user, :pass) unless @proxy_options.empty? - add_ssl(Net::HTTP.new(*params)) + http = add_ssl(Net::HTTP.new(*params)) + http = add_http_options(http) unless @http_options.empty? + http end # Allow for https calls @@ -245,6 +247,20 @@ def add_ssl(http) http end + # Add others http options to http object + # + # * *Args* : + # - +http+ -> HTTP::NET object + # * *Returns* : + # - HTTP::NET object + # + def add_http_options(http) + @http_options.each do |attribute, value| + http.send("#{attribute}=", value) + end + http + end + # Add variable values to the url. # (e.g. /your/api/{variable_value}/call) # Another example: if you have a ruby reserved word, such as true, diff --git a/test/test_ruby_http_client.rb b/test/test_ruby_http_client.rb index a3b5601..aefb667 100644 --- a/test/test_ruby_http_client.rb +++ b/test/test_ruby_http_client.rb @@ -253,6 +253,14 @@ def add_ssl assert_equal(http.verify_mode, OpenSSL::SSL::VERIFY_PEER) end + def test_add_http_options + uri = URI.parse('https://localhost:4010') + http = Net::HTTP.new(uri.host, uri.port) + http = @client_with_options.add_http_options(http) + assert_equal(http.open_timeout, 60) + assert_equal(http.read_timeout, 60) + end + def test__ url1 = @client._('test') assert_equal(['test'], url1.url_path)