Simplify detecting available HTTP client

This commit is contained in:
Mislav Marohnić 2018-08-22 13:09:20 +02:00
parent 655c13b57e
commit 407a74b734

View file

@ -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() {