From 39a03a5131f297b53670bc1c53e87103a9d47ef9 Mon Sep 17 00:00:00 2001 From: "John R. D'Orazio" Date: Mon, 29 Apr 2024 03:38:46 +0200 Subject: [PATCH] try to make RegionalData cors compatible --- LitCalRegionalData.php | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/LitCalRegionalData.php b/LitCalRegionalData.php index 1319217d..c77403f4 100644 --- a/LitCalRegionalData.php +++ b/LitCalRegionalData.php @@ -40,6 +40,7 @@ class LitCalRegionalData { private object $RESPONSE; //The General Index is currently only used for diocesan calendars private ?stdClass $GeneralIndex = null; + private array $AllowedRequestMethods = [ 'GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'OPTIONS' ]; public APICore $APICore; @@ -65,9 +66,14 @@ private function handleRequestedMethod() { $this->handlePutPatchDeleteRequests( RequestMethod::DELETE ); break; case RequestMethod::OPTIONS: - //continue; - break; - default: + if (isset($_SERVER['HTTP_ACCESS_CONTROL_REQUEST_METHOD'])) { + header("Access-Control-Allow-Methods: " . implode( ', ', $this->AllowedRequestMethods )); + } + if (isset($_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS'])) { + header("Access-Control-Allow-Headers: {$_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS']}"); + } + continue; + default: header( $_SERVER[ "SERVER_PROTOCOL" ]." 405 Method Not Allowed", true, 405 ); $errorMessage = '{"error":"You seem to be forming a strange kind of request? Allowed Request Methods are '; $errorMessage .= implode( ' and ', $this->AllowedRequestMethods );