diff options
author | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2021-09-13 01:08:56 +0900 |
---|---|---|
committer | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2021-09-13 01:48:43 +0900 |
commit | c8a1e57af0608c294c5b94f9d158b3d34b94ebb2 (patch) | |
tree | 0456fc0f4fc1d89154a1d0299d3450dcd33ebd3c /tool/downloader.rb | |
parent | 6257090496cf4482637a4c67c1fec4e2ca3a5d8a (diff) | |
download | ruby-c8a1e57af0608c294c5b94f9d158b3d34b94ebb2.tar.gz |
Downloader: accept some RFC 2616 noncompliant dates
Diffstat (limited to 'tool/downloader.rb')
-rw-r--r-- | tool/downloader.rb | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/tool/downloader.rb b/tool/downloader.rb index d09afc5ad7..e9ea00c4c4 100644 --- a/tool/downloader.rb +++ b/tool/downloader.rb @@ -130,6 +130,21 @@ class Downloader options end + def self.httpdate(date) + Time.httpdate(date) + rescue ArgumentError => e + # Some hosts (e.g., zlib.net) return similar to RFC 850 but 4 + # digit year, sometimes. + /\A\s* + (?:Mon|Tues|Wednes|Thurs|Fri|Satur|Sun)day,\x20 + (\d\d)-(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)-(\d{4})\x20 + (\d\d):(\d\d):(\d\d)\x20 + GMT + \s*\z/ix =~ date or raise + warn e.message + Time.utc($3, $2, $1, $4, $5, $6) + end + # Downloader.download(url, name, [dir, [since]]) # # Update a file from url if newer version is available. @@ -231,7 +246,7 @@ class Downloader mtime = data.meta["last-modified"] end if mtime - mtime = Time.httpdate(mtime) + mtime = httpdate(mtime) dest.utime(mtime, mtime) end if $VERBOSE |