false, CURLOPT_FAILONERROR => false, CURLOPT_FOLLOWLOCATION => true, CURLOPT_RETURNTRANSFER => true, CURLOPT_TCP_FASTOPEN => true, CURLOPT_CONNECTTIMEOUT => 2, CURLOPT_MAXREDIRS => 4, CURLOPT_PROTOCOLS => CURLPROTO_HTTP | CURLPROTO_HTTPS, CURLOPT_TIMEOUT => 10, CURLOPT_USERAGENT => 'Mozilla/5.0 (compatible) Misuzu/' . git_tag(), ]); $curlBody = curl_exec($curl); curl_close($curl); $entityTag = '"' . hash('sha256', $curlBody) . '"'; if (!empty($_SERVER['HTTP_IF_NONE_MATCH']) && strtolower($_SERVER['HTTP_IF_NONE_MATCH']) === $entityTag) { http_response_code(304); return; } $finfo = finfo_open(FILEINFO_MIME_TYPE); $fileMime = strtolower(finfo_buffer($finfo, $curlBody)); finfo_close($finfo); if (!in_array($fileMime, $acceptedMimeTypes, true)) { echo render_error(404); return; } $fileSize = strlen($curlBody); $fileName = basename($parsedUrl['path'] ?? "proxied-image-{$expectedHash}"); header("Content-Type: {$fileMime}"); header("Content-Length: {$fileSize}"); header("Content-Disposition: inline; filename=\"{$fileName}\""); header("ETag: {$entityTag}"); echo $curlBody;