Skip to content

Commit

Permalink
Merge pull request #17571 from Homebrew/ignore-last-modified-header-i…
Browse files Browse the repository at this point in the history
…f-invalid
  • Loading branch information
MikeMcQuaid authored Jun 27, 2024
2 parents d293ac1 + 8c9a6e3 commit 5f3af23
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions Library/Homebrew/download_strategy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -518,10 +518,13 @@ def resolve_url_basename_time_file_size(url, timeout: nil)
[*parse_content_disposition.call("Content-Disposition: #{header}")]
end

time = parsed_headers
.flat_map { |headers| [*headers["last-modified"]] }
.map { |t| t.match?(/^\d+$/) ? Time.at(t.to_i) : Time.parse(t) }
.last
time = parsed_headers
.flat_map { |headers| [*headers["last-modified"]] }
.filter_map do |t|
t.match?(/^\d+$/) ? Time.at(t.to_i) : Time.parse(t)
rescue ArgumentError # When `Time.parse` gets a badly formatted date.
nil
end

file_size = parsed_headers
.flat_map { |headers| [*headers["content-length"]&.to_i] }
Expand All @@ -530,7 +533,7 @@ def resolve_url_basename_time_file_size(url, timeout: nil)
is_redirection = url != final_url
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

def _fetch(url:, resolved_url:, timeout:)
Expand Down

0 comments on commit 5f3af23

Please sign in to comment.