CurlDownloadStrategy: Ignore invalid last-modified header values
- Some download locations return a non-standard formatting of date string for the `Last-Modified` header. This causes `Time.parse` to blow up. The user sees `error: argument out of range`. - In this commit we handle the error and return nil, which `filter_map` (equivalent to `.map.compact`) gets rid of and then `time.last` is as normal. - Fixes https://github.com/Homebrew/brew/issues/ 17556.
This commit is contained in:
parent
b780a08774
commit
c8504427cb
@ -520,8 +520,11 @@ class CurlDownloadStrategy < AbstractFileDownloadStrategy
|
|||||||
|
|
||||||
time = parsed_headers
|
time = parsed_headers
|
||||||
.flat_map { |headers| [*headers["last-modified"]] }
|
.flat_map { |headers| [*headers["last-modified"]] }
|
||||||
.map { |t| t.match?(/^\d+$/) ? Time.at(t.to_i) : Time.parse(t) }
|
.filter_map do |t|
|
||||||
.last
|
t.match?(/^\d+$/) ? Time.at(t.to_i) : Time.parse(t)
|
||||||
|
rescue ArgumentError
|
||||||
|
nil
|
||||||
|
end
|
||||||
|
|
||||||
file_size = parsed_headers
|
file_size = parsed_headers
|
||||||
.flat_map { |headers| [*headers["content-length"]&.to_i] }
|
.flat_map { |headers| [*headers["content-length"]&.to_i] }
|
||||||
@ -530,7 +533,7 @@ class CurlDownloadStrategy < AbstractFileDownloadStrategy
|
|||||||
is_redirection = url != final_url
|
is_redirection = url != final_url
|
||||||
basename = filenames.last || parse_basename(final_url, search_query: !is_redirection)
|
basename = filenames.last || parse_basename(final_url, search_query: !is_redirection)
|
||||||
|
|
||||||
@resolved_info_cache[url] = [final_url, basename, time, file_size, is_redirection]
|
@resolved_info_cache[url] = [final_url, basename, time.last, file_size, is_redirection]
|
||||||
end
|
end
|
||||||
|
|
||||||
def _fetch(url:, resolved_url:, timeout:)
|
def _fetch(url:, resolved_url:, timeout:)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user