Commit 407a74b7 authored by Mislav Marohnić's avatar Mislav Marohnić
Browse files

Simplify detecting available HTTP client

parent 655c13b5
Loading
Loading
Loading
Loading
+17 −18
Original line number Diff line number Diff line
@@ -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
    fi
  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
  "${http_client}" "$url" "$file"
  done
  echo "error: please install \`aria2c\`, \`curl\`, or \`wget\` and try again" >&2
  return 1
}

http_head_aria2c() {