Merge pull request #13584 from steveh7812/api-curl-args

use --time-cond when caching the formula api json
This commit is contained in:
Carlo Cabrera 2022-07-21 15:30:39 +08:00 committed by GitHub
commit e7fc86d80f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -30,10 +30,8 @@ module Homebrew
def all_formulae
@all_formulae ||= begin
curl_args = %w[--compressed --silent https://formulae.brew.sh/api/formula.json]
if cached_formula_json_file.exist?
last_modified = cached_formula_json_file.mtime.utc
last_modified = last_modified.strftime("%a, %d %b %Y %H:%M:%S GMT")
curl_args = ["--header", "If-Modified-Since: #{last_modified}", *curl_args]
if cached_formula_json_file.exist? && !cached_formula_json_file.empty?
curl_args.prepend("--time-cond", cached_formula_json_file)
end
curl_download(*curl_args, to: HOMEBREW_CACHE_API/"#{formula_api_path}.json", max_time: 5)