lib/ezclient/request.rb in ezclient-0.12.0 vs lib/ezclient/request.rb in ezclient-0.13.0
- old
+ new
@@ -83,11 +83,11 @@
def http_client
# Only used to build proper HTTP::Request and HTTP::Options instances
@http_client ||= begin
http_client = client.dup
- http_client = http_client.timeout(timeout) if timeout
+ http_client = set_timeout(http_client)
http_client = http_client.basic_auth(basic_auth) if basic_auth
http_client
end
end
@@ -145,9 +145,23 @@
def prepare_headers(headers)
headers = HTTP::Headers.coerce(headers)
headers[:user_agent] ||= "ezclient/#{EzClient::VERSION}"
headers
+ end
+
+ def set_timeout(client)
+ return client unless timeout
+
+ timeout_args =
+ # for HTTP v3
+ if HTTP::Timeout::Global.ancestors.include?(HTTP::Timeout::PerOperation)
+ [:global, read: timeout]
+ else
+ [timeout]
+ end
+
+ client.timeout(*timeout_args)
end
def basic_auth
@basic_auth ||= begin
case options[:basic_auth]