brew.sh: move shared curl speed limit settings here.

This avoids duplication and potentially allows it to be used for various
other `curl` calls.
This commit is contained in:
Mike McQuaid 2023-02-10 17:27:10 +00:00
parent 43a887a7da
commit e301fe8fd8
No known key found for this signature in database
GPG Key ID: 3338A31AFDB1D829
3 changed files with 14 additions and 7 deletions

View File

@ -19,11 +19,6 @@ module Homebrew
HOMEBREW_CACHE_API = (HOMEBREW_CACHE/"api").freeze
# Timeout values to check for dead connections
# We don't use --max-time to support slow connections
JSON_API_SPEED_MARGIN = 100 # bytes/sec
JSON_API_SPEED_TIME = 10 # seconds of downloading under the margin
sig { params(endpoint: String).returns(Hash) }
def fetch(endpoint)
return cache[endpoint] if cache.present? && cache.key?(endpoint)
@ -47,7 +42,11 @@ module Homebrew
retry_count = 0
url = "#{Homebrew::EnvConfig.api_domain}/#{endpoint}"
default_url = "#{HOMEBREW_API_DEFAULT_DOMAIN}/#{endpoint}"
curl_args = %W[--compressed --speed-limit #{JSON_API_SPEED_MARGIN} --speed-time #{JSON_API_SPEED_TIME}]
curl_args = %W[
--compressed
--speed-limit #{ENV.fetch("HOMEBREW_CURL_SPEED_LIMIT")}
--speed-time #{ENV.fetch("HOMEBREW_CURL_SPEED_TIME")}
]
curl_args.prepend("--silent") unless Context.current.debug?
begin

View File

@ -628,6 +628,11 @@ curl_version_output="$(curl --version 2>/dev/null)"
curl_name_and_version="${curl_version_output%% (*}"
HOMEBREW_USER_AGENT_CURL="${HOMEBREW_USER_AGENT} ${curl_name_and_version// //}"
# Timeout values to check for dead connections
# We don't use --max-time to support slow connections
HOMEBREW_CURL_SPEED_LIMIT=100
HOMEBREW_CURL_SPEED_TIME=5
export HOMEBREW_VERSION
export HOMEBREW_DEFAULT_CACHE
export HOMEBREW_CACHE
@ -656,6 +661,8 @@ export HOMEBREW_USER_AGENT_CURL
export HOMEBREW_API_DEFAULT_DOMAIN
export HOMEBREW_BOTTLE_DEFAULT_DOMAIN
export HOMEBREW_MACOS_SYSTEM_RUBY_NEW_ENOUGH
export HOMEBREW_CURL_SPEED_LIMIT
export HOMEBREW_CURL_SPEED_TIME
if [[ -n "${HOMEBREW_MACOS}" && -x "/usr/bin/xcode-select" ]]
then

View File

@ -785,7 +785,8 @@ EOS
fi
curl \
"${CURL_DISABLE_CURLRC_ARGS[@]}" \
--fail --compressed --silent --speed-limit 100 --speed-time 30 \
--fail --compressed --silent \
--speed-limit "${HOMEBREW_CURL_SPEED_LIMIT}" --speed-time "${HOMEBREW_CURL_SPEED_TIME}" \
--location --remote-time --output "${HOMEBREW_CACHE}/api/${formula_or_cask}.json" \
"${time_cond[@]}" \
--user-agent "${HOMEBREW_USER_AGENT_CURL}" \