Skip to content

Commit 6e8265d

Browse files
fix: Mistake on setup http_options for Net::HTTP object when build http (#124)
1 parent 3059289 commit 6e8265d

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

Diff for: lib/ruby_http_client.rb

+17-1
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,9 @@ def make_request(http, request)
227227
def build_http(host, port)
228228
params = [host, port]
229229
params += @proxy_options.values_at(:host, :port, :user, :pass) unless @proxy_options.empty?
230-
add_ssl(Net::HTTP.new(*params))
230+
http = add_ssl(Net::HTTP.new(*params))
231+
http = add_http_options(http) unless @http_options.empty?
232+
http
231233
end
232234

233235
# Allow for https calls
@@ -245,6 +247,20 @@ def add_ssl(http)
245247
http
246248
end
247249

250+
# Add others http options to http object
251+
#
252+
# * *Args* :
253+
# - +http+ -> HTTP::NET object
254+
# * *Returns* :
255+
# - HTTP::NET object
256+
#
257+
def add_http_options(http)
258+
@http_options.each do |attribute, value|
259+
http.send("#{attribute}=", value)
260+
end
261+
http
262+
end
263+
248264
# Add variable values to the url.
249265
# (e.g. /your/api/{variable_value}/call)
250266
# Another example: if you have a ruby reserved word, such as true,

Diff for: test/test_ruby_http_client.rb

+8
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,14 @@ def add_ssl
253253
assert_equal(http.verify_mode, OpenSSL::SSL::VERIFY_PEER)
254254
end
255255

256+
def test_add_http_options
257+
uri = URI.parse('https://localhost:4010')
258+
http = Net::HTTP.new(uri.host, uri.port)
259+
http = @client_with_options.add_http_options(http)
260+
assert_equal(http.open_timeout, 60)
261+
assert_equal(http.read_timeout, 60)
262+
end
263+
256264
def test__
257265
url1 = @client._('test')
258266
assert_equal(['test'], url1.url_path)

0 commit comments

Comments
 (0)