diff --git a/htdocs/api/class/api.class.php b/htdocs/api/class/api.class.php index b4e1abdbadb..1b3b3f61a31 100644 --- a/htdocs/api/class/api.class.php +++ b/htdocs/api/class/api.class.php @@ -110,6 +110,8 @@ class DolibarrApi unset($object->ismultientitymanaged); unset($object->restrictiononfksoc); unset($object->table_rowid); + unset($object->pass); + unset($object->pass_indatabase); // Remove linkedObjects. We should already have linkedObjectsIds that avoid huge responses unset($object->linkedObjects); diff --git a/htdocs/api/index.php b/htdocs/api/index.php index d19754f9c35..d3fcd9b017d 100644 --- a/htdocs/api/index.php +++ b/htdocs/api/index.php @@ -343,14 +343,32 @@ if (!empty($reg[1]) && ($reg[1] != 'explorer' || ($reg[2] != '/swagger.json' && //exit; // We do not want that restler outputs 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'])); +// If API_DISABLE_COMPRESSION is set, returnResponse is false => It use default handling so output result directly. +$usecompression = (empty($conf->global->API_DISABLE_COMPRESSION) && !empty($_SERVER['HTTP_ACCEPT_ENCODING'])); +$foundonealgorithm = 0; +if (strpos($_SERVER['HTTP_ACCEPT_ENCODING'], 'br') !== false && is_callable('brotli_compress')) { + $foundonealgorithm++; +} +if (strpos($_SERVER['HTTP_ACCEPT_ENCODING'], 'bz') !== false && is_callable('bzcompress')) { + $foundonealgorithm++; +} +if (strpos($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip') !== false && is_callable('gzencode')) { + $foundonealgorithm++; +} +if (!$foundonealgorithm) { + $usecompression = false; +} + +//dol_syslog('We found some compression algoithm: '.$foundonealgorithm.' -> usecompression='.$usecompression, LOG_DEBUG); + +Luracast\Restler\Defaults::$returnResponse = $usecompression; // 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 (Luracast\Restler\Defaults::$returnResponse) { - // We try to compress data + // We try to compress the data received data if (strpos($_SERVER['HTTP_ACCEPT_ENCODING'], 'br') !== false && is_callable('brotli_compress')) { header('Content-Encoding: br'); $result = brotli_compress($result, 11, BROTLI_TEXT); @@ -360,6 +378,10 @@ if (Luracast\Restler\Defaults::$returnResponse) { } elseif (strpos($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip') !== false && is_callable('gzencode')) { header('Content-Encoding: gzip'); $result = gzencode($result, 9); + } else { + header('Content-Encoding: text/html'); + print "No compression method found. Try to disable compression by adding API_DISABLE_COMPRESSION=1"; + exit(0); } // Restler did not output data yet, we return it now diff --git a/htdocs/core/class/html.formother.class.php b/htdocs/core/class/html.formother.class.php index bd90c9a5ed8..c25f5bdb719 100644 --- a/htdocs/core/class/html.formother.class.php +++ b/htdocs/core/class/html.formother.class.php @@ -57,10 +57,10 @@ class FormOther } /** - * Return HTML code for scanner tool. + * Return the HTML code for scanner tool. * This must be called into an existing