summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNobuyoshi Nakada <nobu@ruby-lang.org>2021-10-28 17:42:36 +0900
committerNobuyoshi Nakada <nobu@ruby-lang.org>2021-10-28 17:42:36 +0900
commite76e1d3ce4bf65b3c7f56e09dd5f51b79538df18 (patch)
tree78f6db13f5000ccedd42ee22ce1f0fa05319a723
parent1d666ed50f8b4b3779583381882a0b3edd3cff0e (diff)
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?).
-rw-r--r--tool/downloader.rb13
1 files changed, 8 insertions, 5 deletions
diff --git a/tool/downloader.rb b/tool/downloader.rb
index e9ea00c4c4..d3a9f75637 100644
--- a/tool/downloader.rb
+++ b/tool/downloader.rb
@@ -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