#!/usr/bin/env bash # Probes the edge. ok/FAIL lines (privacy denials and gates) set the exit # status; show/hdr lines depend on data, so diff two runs instead. # caddy/edge_test.sh [curl options...] # e.g. https://www.$DOMAIN --resolve www.$DOMAIN:443:127.0.0.1 (on stpvm) # https://localhost -k (dev) # Optional env: EDGE_APEX, EDGE_HTTP, EDGE_COOKIE (admin session), # EDGE_UPLOAD (an existing upload's name). Read-only: GETs plus one POST that # the edge refuses. set -u if [ $# -lt 1 ]; then echo "usage: $0 [curl options...]" >&2 exit 2 fi BASE=${1%/} shift CURL_OPTS=("$@") FAILED=0 # The www host, without scheme or port. BASE_HOST=$(printf '%s' "$BASE" | sed -E 's#^[a-z]+://([^/:]+).*#\1#') # " "; a redirect to www is shown as its path alone. probe() { local url=$1 out shift out=$(curl -sS -o /dev/null --max-time 15 -w '%{http_code} %{redirect_url}' \ "${CURL_OPTS[@]}" "$@" "$url" 2>/dev/null) || out=ERR printf '%s' "$out" | sed -E "s#^([0-9]+) [a-z]+://$BASE_HOST(:[0-9]+)?/#\\1 /#" } # The first value of one response header, or "-". header_of() { local name=$1 url=$2 value shift 2 value=$(curl -sS -o /dev/null -D - --max-time 15 "${CURL_OPTS[@]}" "$@" "$url" 2>/dev/null | tr -d '\r' | grep -i "^$name:" | head -n 1 | cut -d: -f2- | sed 's/^ //') printf '%s' "${value:--}" } # must