lib/u3d/utils.rb in u3d-1.0.17 vs lib/u3d/utils.rb in u3d-1.0.18
- old
+ new
@@ -56,11 +56,11 @@
response = nil
request = nil
uri = URI(url)
begin
use_ssl = /^https/.match(url)
- Net::HTTP.start(uri.host, uri.port, use_ssl: use_ssl) do |http|
+ Net::HTTP.start(uri.host, uri.port, http_opts(use_ssl: use_ssl)) do |http|
request = http_request_class http_method, uri
request_headers.each do |k, v|
request[k] = v
end
response = http.request request
@@ -91,11 +91,11 @@
File.open(path, 'wb') do |f|
uri = URI(url)
current = 0
last_print_update = 0
print_progress = UI.interactive? || U3dCore::Globals.verbose?
- Net::HTTP.start(uri.host, uri.port, use_ssl: uri.scheme == 'https') do |http|
+ Net::HTTP.start(uri.host, uri.port, http_opts(use_ssl: uri.scheme == 'https')) do |http|
request = Net::HTTP::Get.new uri
http.request request do |response|
begin
# override with actual results, this should help with
# innacurrate declared sizes, especially on Windows platform
@@ -127,11 +127,11 @@
def get_url_content_length(url)
UI.verbose "get_url_content_length #{url}"
uri = URI(url)
size = nil
- Net::HTTP.start(uri.host, uri.port) do |http|
+ Net::HTTP.start(uri.host, uri.port, http_opts) do |http|
response = http.request_head url
size = Integer(response['Content-Length'])
end
UI.verbose "get_url_content_length #{url}: #{size}"
size
@@ -201,9 +201,29 @@
Filesize.from(filesize.round.to_s + ' B').pretty
end
def windows_path(path)
path.gsub(%r{\/(\d)}, '/\\\\\1').tr('/', '\\')
+ end
+
+ private
+
+ def http_max_retries
+ ENV['U3D_HTTP_MAX_RETRIES'].to_i if ENV['U3D_HTTP_MAX_RETRIES']
+ end
+
+ def http_read_timeout
+ return ENV['U3D_HTTP_READ_TIMEOUT'].to_i if ENV['U3D_HTTP_READ_TIMEOUT']
+ 300
+ end
+
+ def http_opts(opt = {})
+ # the keys are #ca_file, #ca_path, cert, #cert_store, ciphers, #close_on_empty_response, key, #open_timeout,
+ # #read_timeout, #ssl_timeout, #ssl_version, use_ssl, #verify_callback, #verify_depth and verify_mode
+ opt[:max_retries] = http_max_retries if http_max_retries
+ opt[:read_timeout] = http_read_timeout if http_read_timeout
+ UI.verbose "Using http opts: #{opt}"
+ opt
end
end
end
# rubocop:enable ModuleLength
end