mirror of https://github.com/MISP/MISP
Merge pull request #5561 from JakubOnderka/is_rest_cache
chg: [internal] Cache result of AppController::_isRest methodpull/5835/head
commit
f30959f274
|
@ -57,6 +57,8 @@ class AppController extends Controller
|
|||
public $baseurl = '';
|
||||
public $sql_dump = false;
|
||||
|
||||
private $isRest = null;
|
||||
|
||||
// Used for _isAutomation(), a check that returns true if the controller & action combo matches an action that is a non-xml and non-json automation method
|
||||
// This is used to allow authentication via headers for methods not covered by _isRest() - as that only checks for JSON and XML formats
|
||||
public $automationArray = array(
|
||||
|
@ -680,6 +682,11 @@ class AppController extends Controller
|
|||
|
||||
protected function _isRest()
|
||||
{
|
||||
// This method is surprisingly slow and called many times for one request, so it make sense to cache the result.
|
||||
if ($this->isRest !== null) {
|
||||
return $this->isRest;
|
||||
}
|
||||
|
||||
$api = $this->__isApiFunction($this->request->params['controller'], $this->request->params['action']);
|
||||
if (isset($this->RequestHandler) && ($api || $this->RequestHandler->isXml() || $this->_isJson() || $this->_isCsv())) {
|
||||
if ($this->_isJson()) {
|
||||
|
@ -687,8 +694,10 @@ class AppController extends Controller
|
|||
throw new MethodNotAllowedException('Invalid JSON input. Make sure that the JSON input is a correctly formatted JSON string. This request has been blocked to avoid an unfiltered request.');
|
||||
}
|
||||
}
|
||||
$this->isRest = true;
|
||||
return true;
|
||||
} else {
|
||||
$this->isRest = false;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue