From 25c8430b19805b0a1dd4aed590ab848723bf47de Mon Sep 17 00:00:00 2001 From: Guy Halse Date: Tue, 15 Aug 2023 10:12:28 +0200 Subject: [PATCH] Allow encoding in Content-Type --- fetchmetadata.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fetchmetadata.php b/fetchmetadata.php index f6070da..4b45a46 100644 --- a/fetchmetadata.php +++ b/fetchmetadata.php @@ -79,12 +79,12 @@ function badGateway($message) if ($data === false) badGateway(curl_error($curl)); -if (!in_array(curl_getinfo($curl, CURLINFO_CONTENT_TYPE), $SUPPORTED_CONTENT_TYPES)) +if (!in_array(preg_replace('/\s*;.*$/', '', curl_getinfo($curl, CURLINFO_CONTENT_TYPE)), $SUPPORTED_CONTENT_TYPES)) badGateway('Got unsupported content type. Only accept: ' . implode(', ', $SUPPORTED_CONTENT_TYPES)); http_response_code(curl_getinfo($curl, CURLINFO_RESPONSE_CODE)); header('Status: ' . curl_getinfo($curl, CURLINFO_RESPONSE_CODE)); -header('Content-Type: text/plain'); /* edit wants plain text, not DOM */ +header('Content-Type: text/plain' . preg_replace('/^[^;]+/', '', curl_getinfo($curl, CURLINFO_CONTENT_TYPE))); /* edit wants plain text, not DOM; preserve encoding */ header('Content-Length: ' . curl_getinfo($curl, CURLINFO_CONTENT_LENGTH_DOWNLOAD)); header('X-Location: ' . curl_getinfo($curl, CURLINFO_EFFECTIVE_URL)); print substr($data, curl_getinfo($curl, CURLINFO_HEADER_SIZE));