#!/bin/sh
# Read-only helper: inspect the response headers for one HTTP(S) URL.
set -eu

if [ "$#" -ne 1 ]; then
  echo "usage: $0 URL" >&2
  exit 2
fi

case "$1" in
  http://*|https://*) ;;
  *)
    echo "URL must start with http:// or https://" >&2
    exit 2
    ;;
esac

curl --silent --show-error --location --max-time 20 \
  --dump-header - --output /dev/null \
  --write-out '\nHTTP_STATUS %{http_code}\nFINAL_URL %{url_effective}\n' \
  "$1"
