private function buildHttpResponse(AjaxResponse $api_response, $allow_removing_headers = null)
{
if ($api_response->isCancelled()) {
return new JsonResponse(['error' => "The response was cancelled"], 400);
}
$response = new JsonResponse($api_response->getData());
$ttl = $api_response->getTtl();
if ($ttl > 0) {
// Required to remove headers set by PHP session
if (!isset($allow_removing_headers)) {
$allow_removing_headers = !elgg()->isTestingApplication();
}
if ($allow_removing_headers) {
header_remove('Expires');
header_remove('Pragma');
header_remove('Cache-Control');
}
// JsonRequest sets a default Cache-Control header we don't want
$response->headers->remove('Cache-Control');
$response->setClientTtl($ttl);
// if we don't set Expires, Apache will add a far-off max-age and Expires for us.
$response->headers->set('Expires', gmdate('D, d M Y H:i:s \\G\\M\\T', time() + $ttl));
}
return $response;
}