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