From 94b98403aba7cf7aa7733496de090af9f870fc9b Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 25 Mar 2021 12:52:35 +0100 Subject: [PATCH] Update index.php --- htdocs/api/index.php | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/htdocs/api/index.php b/htdocs/api/index.php index 739db3e465d..2ed7d2e08f8 100644 --- a/htdocs/api/index.php +++ b/htdocs/api/index.php @@ -308,14 +308,15 @@ if (!empty($reg[1]) && ($reg[1] != 'explorer' || ($reg[2] != '/swagger.json' && //var_dump($api->r->apiVersionMap); //exit; -//We do not want that restler return data if we want to compress it -Luracast\Restler\Defaults::$returnResponse = empty($conf->global->API_DISABLE_COMPRESSION); +// We do not want that restler output data if we use native compression (default behaviour) but we want to have it returned into a string. +Luracast\Restler\Defaults::$returnResponse = (empty($conf->global->API_DISABLE_COMPRESSION) && !empty($_SERVER['HTTP_ACCEPT_ENCODING'])); // Call API (we suppose we found it). // The handle will use the file api/temp/routes.php to get data to run the API. If the file exists and the entry for API is not found, it will return 404. $result = $api->r->handle(); -if (empty($conf->global->API_DISABLE_COMPRESSION) && isset($_SERVER['HTTP_ACCEPT_ENCODING'])) { - //We try to compress data + +if (Luracast\Restler\Defaults::$returnResponse) { + // We try to compress data if (strpos($_SERVER['HTTP_ACCEPT_ENCODING'], 'br') !== false && is_callable('brotli_compress')) { header('Content-Encoding: br'); $result = brotli_compress($result, 11, BROTLI_TEXT); @@ -327,10 +328,7 @@ if (empty($conf->global->API_DISABLE_COMPRESSION) && isset($_SERVER['HTTP_ACCEPT $result = gzencode($result, 9); } -} - -if(Luracast\Restler\Defaults::$returnResponse) { - //Restler did not output data,we return it + // Restler did not output data yet, we return it now echo $result; }