Skip to content

fix: Mistake on setup http_options for Net::HTTP object when build http #124

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jan 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion lib/ruby_http_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand Down
8 changes: 8 additions & 0 deletions test/test_ruby_http_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down