mirror of
https://github.com/Homebrew/brew.git
synced 2025-07-14 16:09:03 +08:00
Use curl options where appropriate
This commit is contained in:
parent
d44979fa67
commit
f88966a8a5
@ -27,7 +27,7 @@ module Homebrew
|
|||||||
return cache[endpoint] if cache.present? && cache.key?(endpoint)
|
return cache[endpoint] if cache.present? && cache.key?(endpoint)
|
||||||
|
|
||||||
api_url = "#{API_DOMAIN}/#{endpoint}"
|
api_url = "#{API_DOMAIN}/#{endpoint}"
|
||||||
output = Utils::Curl.curl_output("--fail", "--max-time", "5", api_url)
|
output = Utils::Curl.curl_output("--fail", api_url, max_time: 5)
|
||||||
raise ArgumentError, "No file found at #{Tty.underline}#{api_url}#{Tty.reset}" unless output.success?
|
raise ArgumentError, "No file found at #{Tty.underline}#{api_url}#{Tty.reset}" unless output.success?
|
||||||
|
|
||||||
cache[endpoint] = if json
|
cache[endpoint] = if json
|
||||||
|
@ -558,7 +558,7 @@ class CurlDownloadStrategy < AbstractFileDownloadStrategy
|
|||||||
end
|
end
|
||||||
|
|
||||||
def curl(*args, **options)
|
def curl(*args, **options)
|
||||||
args << "--connect-timeout" << "15" unless mirrors.empty?
|
options[:connect_timeout] = 15 unless mirrors.empty?
|
||||||
super(*_curl_args, *args, **_curl_opts, **command_output_options, **options)
|
super(*_curl_args, *args, **_curl_opts, **command_output_options, **options)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -39,8 +39,6 @@ module Homebrew
|
|||||||
DEFAULT_CURL_ARGS = [
|
DEFAULT_CURL_ARGS = [
|
||||||
# Follow redirections to handle mirrors, relocations, etc.
|
# Follow redirections to handle mirrors, relocations, etc.
|
||||||
"--location",
|
"--location",
|
||||||
"--connect-timeout", CURL_CONNECT_TIMEOUT,
|
|
||||||
"--max-time", CURL_MAX_TIME
|
|
||||||
].freeze
|
].freeze
|
||||||
|
|
||||||
# `curl` arguments used in `Strategy#page_headers` method.
|
# `curl` arguments used in `Strategy#page_headers` method.
|
||||||
@ -67,6 +65,8 @@ module Homebrew
|
|||||||
debug: false,
|
debug: false,
|
||||||
verbose: false,
|
verbose: false,
|
||||||
timeout: CURL_PROCESS_TIMEOUT,
|
timeout: CURL_PROCESS_TIMEOUT,
|
||||||
|
connect_timeout: CURL_CONNECT_TIMEOUT,
|
||||||
|
max_time: CURL_MAX_TIME,
|
||||||
retries: 0,
|
retries: 0,
|
||||||
}.freeze
|
}.freeze
|
||||||
|
|
||||||
|
@ -214,8 +214,13 @@ module Utils
|
|||||||
if url != secure_url
|
if url != secure_url
|
||||||
user_agents.each do |user_agent|
|
user_agents.each do |user_agent|
|
||||||
secure_details = begin
|
secure_details = begin
|
||||||
curl_http_content_headers_and_checksum(secure_url, specs: specs, hash_needed: true,
|
curl_http_content_headers_and_checksum(
|
||||||
user_agent: user_agent, use_homebrew_curl: use_homebrew_curl)
|
secure_url,
|
||||||
|
specs: specs,
|
||||||
|
hash_needed: true,
|
||||||
|
use_homebrew_curl: use_homebrew_curl,
|
||||||
|
user_agent: user_agent,
|
||||||
|
)
|
||||||
rescue Timeout::Error
|
rescue Timeout::Error
|
||||||
next
|
next
|
||||||
end
|
end
|
||||||
@ -231,8 +236,13 @@ module Utils
|
|||||||
details = nil
|
details = nil
|
||||||
user_agents.each do |user_agent|
|
user_agents.each do |user_agent|
|
||||||
details =
|
details =
|
||||||
curl_http_content_headers_and_checksum(url, specs: specs, hash_needed: hash_needed,
|
curl_http_content_headers_and_checksum(
|
||||||
user_agent: user_agent, use_homebrew_curl: use_homebrew_curl)
|
url,
|
||||||
|
specs: specs,
|
||||||
|
hash_needed: hash_needed,
|
||||||
|
use_homebrew_curl: use_homebrew_curl,
|
||||||
|
user_agent: user_agent,
|
||||||
|
)
|
||||||
break if http_status_ok?(details[:status])
|
break if http_status_ok?(details[:status])
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -297,16 +307,21 @@ module Utils
|
|||||||
"The #{url_type} #{url} may be able to use HTTPS rather than HTTP. Please verify it in a browser."
|
"The #{url_type} #{url} may be able to use HTTPS rather than HTTP. Please verify it in a browser."
|
||||||
end
|
end
|
||||||
|
|
||||||
def curl_http_content_headers_and_checksum(url, specs: {}, hash_needed: false,
|
def curl_http_content_headers_and_checksum(
|
||||||
user_agent: :default, use_homebrew_curl: false)
|
url, specs: {}, hash_needed: false,
|
||||||
|
use_homebrew_curl: false, user_agent: :default
|
||||||
|
)
|
||||||
file = Tempfile.new.tap(&:close)
|
file = Tempfile.new.tap(&:close)
|
||||||
|
|
||||||
specs = specs.flat_map { |option, argument| ["--#{option.to_s.tr("_", "-")}", argument] }
|
specs = specs.flat_map { |option, argument| ["--#{option.to_s.tr("_", "-")}", argument] }
|
||||||
max_time = hash_needed ? "600" : "25"
|
max_time = hash_needed ? 600 : 25
|
||||||
output, _, status = curl_output(
|
output, _, status = curl_output(
|
||||||
*specs, "--dump-header", "-", "--output", file.path, "--location",
|
*specs, "--dump-header", "-", "--output", file.path, "--location", url,
|
||||||
"--connect-timeout", "15", "--max-time", max_time, "--retry-max-time", max_time, url,
|
use_homebrew_curl: use_homebrew_curl,
|
||||||
user_agent: user_agent, use_homebrew_curl: use_homebrew_curl
|
connect_timeout: 15,
|
||||||
|
max_time: max_time,
|
||||||
|
retry_max_time: max_time,
|
||||||
|
user_agent: user_agent
|
||||||
)
|
)
|
||||||
|
|
||||||
status_code = :unknown
|
status_code = :unknown
|
||||||
|
Loading…
x
Reference in New Issue
Block a user