mirror of
https://github.com/rbenv/ruby-build.git
synced 2025-10-24 23:00:52 +02:00
Simplify detecting available HTTP client
This commit is contained in:
parent
655c13b57e
commit
407a74b734
1 changed files with 17 additions and 18 deletions
|
|
@ -300,26 +300,25 @@ verify_checksum() {
|
|||
|
||||
http() {
|
||||
local method="$1"
|
||||
local url="$2"
|
||||
local file="$3"
|
||||
[ -n "$url" ] || return 1
|
||||
[ -n "$2" ] || return 1
|
||||
shift 1
|
||||
|
||||
local http_client
|
||||
if [ -n "${RUBY_BUILD_HTTP_CLIENT}" ]; then
|
||||
http_client="http_${method}_${RUBY_BUILD_HTTP_CLIENT}"
|
||||
else
|
||||
if type aria2c &>/dev/null; then
|
||||
http_client="http_${method}_aria2c"
|
||||
elif type curl &>/dev/null; then
|
||||
http_client="http_${method}_curl"
|
||||
elif type wget &>/dev/null; then
|
||||
http_client="http_${method}_wget"
|
||||
else
|
||||
echo "error: please install \`aria2c\`, \`curl\` or \`wget\` and try again" >&2
|
||||
exit 1
|
||||
RUBY_BUILD_HTTP_CLIENT="${RUBY_BUILD_HTTP_CLIENT:-$(detect_http_client)}"
|
||||
[ -n "$RUBY_BUILD_HTTP_CLIENT" ] || return 1
|
||||
|
||||
"http_${method}_${RUBY_BUILD_HTTP_CLIENT}" "$@"
|
||||
}
|
||||
|
||||
detect_http_client() {
|
||||
local client
|
||||
for client in aria2c curl wget; do
|
||||
if type "$client" &>/dev/null; then
|
||||
echo "$client"
|
||||
return
|
||||
fi
|
||||
fi
|
||||
"${http_client}" "$url" "$file"
|
||||
done
|
||||
echo "error: please install \`aria2c\`, \`curl\`, or \`wget\` and try again" >&2
|
||||
return 1
|
||||
}
|
||||
|
||||
http_head_aria2c() {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue