/** Akamai WAF/geo block pages — must not inject mirror script into these. */
export function isAkamaiBlockedResponse(
  statusCode: number,
  headers: Record<string, string | string[] | undefined>,
  body: Buffer,
): boolean {
  if (statusCode === 451) return true;
  const blockReason = String(headers['block-reason'] ?? headers['Block-Reason'] ?? '');
  if (blockReason) return true;
  if (body.length > 64_000) return false;
  const text = body.toString('utf8', 0, Math.min(body.length, 4096));
  return (
    /<TITLE>\s*Access Denied\s*<\/TITLE>/i.test(text) ||
    /<H1>\s*Access Denied\s*<\/H1>/i.test(text) ||
    /\b0\.[0-9a-f]+\.[0-9]+\.[0-9a-f]+\b/i.test(text)
  );
}
