mirror of
https://github.com/Combodo/iTop.git
synced 2026-04-24 02:58:43 +02:00
N°6204 - Fix REST/JSON API crash when using JSON-P and iBackofficeDictXXX interfaces
This commit is contained in:
@@ -29,6 +29,7 @@ class JsonPage extends WebPage
|
||||
{
|
||||
$oKpi = new ExecutionKPI();
|
||||
parent::__construct('');
|
||||
$this->sContentType = 'application/json';
|
||||
$oKpi->ComputeStats(get_class($this).' creation', 'JsonPage');
|
||||
}
|
||||
|
||||
@@ -78,29 +79,48 @@ class JsonPage extends WebPage
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
* Output the headers
|
||||
*
|
||||
* @return void
|
||||
* @since 3.1.0
|
||||
*/
|
||||
public function output()
|
||||
protected function OutputHeaders(): void
|
||||
{
|
||||
$oKpi = new ExecutionKPI();
|
||||
$this->add_header('Content-type: application/json');
|
||||
$this->add_header('Content-type: ' . $this->sContentType);
|
||||
|
||||
foreach ($this->a_headers as $s_header) {
|
||||
header($s_header);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string Content to output
|
||||
* @since 3.1.0
|
||||
*/
|
||||
protected function ComputeContent(): string
|
||||
{
|
||||
$aScripts = array_merge($this->a_init_scripts, $this->a_scripts, $this->a_ready_scripts);
|
||||
|
||||
$aJson = $this->bOutputDataOnly ? $this->aData : [
|
||||
'data' => $this->aData,
|
||||
'scripts' => $aScripts,
|
||||
];
|
||||
$sJSON = json_encode($aJson);
|
||||
$oKpi->ComputeAndReport(get_class($this).' output');
|
||||
|
||||
echo $sJSON;
|
||||
$oKpi->ComputeAndReport('Echoing ('.round(strlen($sJSON) / 1024).' Kb)');
|
||||
ExecutionKPI::ReportStats();
|
||||
return json_encode($aJson);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function output()
|
||||
{
|
||||
$oKpi = new ExecutionKPI();
|
||||
$this->OutputHeaders();
|
||||
$sContent = $this->ComputeContent();
|
||||
$oKpi->ComputeAndReport(get_class($this).' output');
|
||||
|
||||
echo $sContent;
|
||||
$oKpi->ComputeAndReport('Echoing ('.round(strlen($sContent) / 1024).' Kb)');
|
||||
ExecutionKPI::ReportStats();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user