1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

Downloader: retry when RFC 2616 noncompliant dates [ci skip]

zlib.net rarely returns the current time in RFC 2616 noncompliant
format in the response header, and the checksum does not match in
that case (maybe creating the tarball on the fly?).
This commit is contained in:
Nobuyoshi Nakada 2021-10-28 17:42:36 +09:00
parent 1d666ed50f
commit e76e1d3ce4
No known key found for this signature in database
GPG key ID: 7CD2805BFA3770C6

View file

@ -211,9 +211,15 @@ class Downloader
$stdout.print "downloading #{name} ... "
$stdout.flush
end
mtime = nil
options = options.merge(http_options(file, since.nil? ? true : since))
begin
data = with_retry(10) do
url.read(options.merge(http_options(file, since.nil? ? true : since)))
data = url.read(options)
if mtime = data.meta["last-modified"]
mtime = Time.httpdate(mtime)
end
data
end
rescue OpenURI::HTTPError => http_error
if http_error.message =~ /^304 / # 304 Not Modified
@ -237,16 +243,13 @@ class Downloader
end
raise
end
mtime = nil
dest = (cache_save && cache && !cache.exist? ? cache : file)
dest.parent.mkpath
dest.open("wb", 0600) do |f|
f.write(data)
f.chmod(mode_for(data))
mtime = data.meta["last-modified"]
end
if mtime
mtime = httpdate(mtime)
dest.utime(mtime, mtime)
end
if $VERBOSE
@ -328,7 +331,7 @@ class Downloader
times = 0
begin
block.call
rescue Errno::ETIMEDOUT, SocketError, OpenURI::HTTPError, Net::ReadTimeout, Net::OpenTimeout => e
rescue Errno::ETIMEDOUT, SocketError, OpenURI::HTTPError, Net::ReadTimeout, Net::OpenTimeout, ArgumentError => e
raise if e.is_a?(OpenURI::HTTPError) && e.message !~ /^50[023] / # retry only 500, 502, 503 for http error
times += 1
if times <= max_times