12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
# File 'lib/bootic_cli/utils.rb', line 12
def self.fetch_http_file(href, attempt: 1, skip_verify: false)
uri = URI.parse(href)
opts = REQUEST_OPTS.merge({
verify_mode: skip_verify ? OpenSSL::SSL::VERIFY_NONE : OpenSSL::SSL::VERIFY_PEER,
use_ssl: uri.port == 443
})
Net::HTTP.start(uri.host, uri.port, opts) do |http|
resp = http.get(uri.path)
raise "Invalid response: #{resp.code}" unless resp.code.to_i == 200
StringIO.new(resp.body)
end
rescue Net::OpenTimeout, Net::ReadTimeout => e
raise if attempt > MAX_FETCH_ATTEMPTS fetch_http_file(href, attempt: attempt + 1)
rescue OpenSSL::SSL::SSLError => e
fetch_http_file(href, attempt: attempt + 1, skip_verify: true)
end
|