#!/usr/bin/env bash
# Pass 9: resolve redirect targets for dmark + ssc, then warm the target
echo "=== PASS9 REDIRECT CHECK $(date -u '+%H:%M:%S UTC') ==="
for U in https://dmark.id/ https://surabaya-skincentre.com/; do
  LOC=$(curl -4 --http1.1 -s -o /dev/null --connect-timeout 6 --max-time 20 -D - "$U" 2>/dev/null | grep -i '^location:' | tr -d '\r')
  echo "${U} -> ${LOC:-no-location}"
done
echo "--- warming targets"
for U in https://www.dmark.id/ https://www.surabaya-skincentre.com/; do
  OUT=$(curl -4 --http1.1 -sL -o /dev/null --connect-timeout 6 --max-time 60 \
        -D /tmp/ben_hdr9_$$.txt -w '%{http_code} t=%{time_total} size=%{size_download}' "$U" 2>/dev/null)
  CF=$(grep -i '^cf-cache-status' /tmp/ben_hdr9_$$.txt | tr -d '\r' | head -1)
  echo "${U} | ${OUT} | ${CF:-no-cf-hdr}"
done
rm -f /tmp/ben_hdr9_$$.txt
echo "=== DONE $(date -u '+%H:%M:%S UTC') ==="
