From b619c754a411515667923028d3ec685835b1351e Mon Sep 17 00:00:00 2001 From: Erik Amaru Ortiz Date: Fri, 21 Feb 2014 19:28:16 -0400 Subject: [PATCH] Adding "Cross Domain AJAX" requests support for API Dispatcher --- gulliver/system/class.bootstrap.php | 17 +++++++++++++++++ gulliver/system/class.g.php | 2 +- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/gulliver/system/class.bootstrap.php b/gulliver/system/class.bootstrap.php index af37fe47d..67fd09fb8 100644 --- a/gulliver/system/class.bootstrap.php +++ b/gulliver/system/class.bootstrap.php @@ -1083,6 +1083,23 @@ class Bootstrap */ public function dispatchApiService($uri, $version = '1.0') { + // to handle a request with "OPTIONS" method + + if ($_SERVER['REQUEST_METHOD'] === 'OPTIONS') { + header('Access-Control-Allow-Methods: GET, POST, PUT, DELETE, OPTIONS, HEADERS'); + header('Access-Control-Allow-Headers: authorization, content-type'); + header("Access-Control-Allow-Credentials", "false"); + header('Access-Control-Max-Age: 60'); + die(); + } + + /* + * Enable this header to allow "Cross Domain AJAX" requests; + * This works because processmaker is handling correctly requests with method 'OPTIONS' + * that automatically is sent by a client using XmlHttpRequest or similar. + */ + header('Access-Control-Allow-Origin: *'); + /* * $servicesDir contains directory where Services Classes are allocated */ diff --git a/gulliver/system/class.g.php b/gulliver/system/class.g.php index 7544e4a9e..5788d95f2 100755 --- a/gulliver/system/class.g.php +++ b/gulliver/system/class.g.php @@ -2609,7 +2609,7 @@ class G * @param integer $permission * @return void */ - public function uploadFile ($file, $path, $nameToSave, $permission = 0660) + public static function uploadFile ($file, $path, $nameToSave, $permission = 0660) { try { if ($file == '') {