N°6204 - Fix REST/JSON API crash when using JSON-P and iBackofficeDictXXX interfaces

This commit is contained in:
Molkobain
2023-04-18 15:32:24 +02:00
parent d46d1db8e4
commit 51617113eb
12 changed files with 170 additions and 92 deletions

View File

@@ -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();
}
}