#!/usr/bin/env bash
# Shared curl helpers for deploy / Apache diagnostics.
# shellcheck disable=SC2034

# curl https://127.0.0.1 with Host: header does NOT select the correct SSL vhost on
# multi-site servers (SNI is required). Use --resolve to hit the intended vhost.
curl_vhost_https() {
  local hostname=$1
  local url_path=$2
  local timeout="${3:-10}"
  curl -sS -o /dev/null -w '%{http_code}' --connect-timeout "$timeout" --max-time "$((timeout * 3))" \
    --resolve "${hostname}:443:127.0.0.1" \
    "https://${hostname}${url_path}" 2>/dev/null || echo 000
}

curl_http_code() {
  curl -sS -o /dev/null -w '%{http_code}' --connect-timeout 10 --max-time 30 "$1" 2>/dev/null || echo 000
}
