[前][次][番号順一覧][スレッド一覧]

ruby-changes:67962

From: Nobuyoshi <ko1@a...>
Date: Mon, 13 Sep 2021 01:51:53 +0900 (JST)
Subject: [ruby-changes:67962] c8a1e57af0 (master): Downloader: accept some RFC 2616 noncompliant dates

https://git.ruby-lang.org/ruby.git/commit/?id=c8a1e57af0

From c8a1e57af0608c294c5b94f9d158b3d34b94ebb2 Mon Sep 17 00:00:00 2001
From: Nobuyoshi Nakada <nobu@r...>
Date: Mon, 13 Sep 2021 01:08:56 +0900
Subject: Downloader: accept some RFC 2616 noncompliant dates

---
 tool/downloader.rb | 17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)

diff --git a/tool/downloader.rb b/tool/downloader.rb
index d09afc5..e9ea00c 100644
--- a/tool/downloader.rb
+++ b/tool/downloader.rb
@@ -130,6 +130,21 @@ class Downloader https://github.com/ruby/ruby/blob/trunk/tool/downloader.rb#L130
     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 https://github.com/ruby/ruby/blob/trunk/tool/downloader.rb#L246
       mtime = data.meta["last-modified"]
     end
     if mtime
-      mtime = Time.httpdate(mtime)
+      mtime = httpdate(mtime)
       dest.utime(mtime, mtime)
     end
     if $VERBOSE
-- 
cgit v1.1


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]