Do not execute controller if the response is already sent
This commit is contained in:
@@ -26,7 +26,10 @@ class Runner extends Base
|
|||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
$this->executeMiddleware();
|
$this->executeMiddleware();
|
||||||
$this->executeController();
|
|
||||||
|
if (!$this->response->isResponseAlreadySent()) {
|
||||||
|
$this->executeController();
|
||||||
|
}
|
||||||
} catch (PageNotFoundException $e) {
|
} catch (PageNotFoundException $e) {
|
||||||
$controllerObject = new AppController($this->container);
|
$controllerObject = new AppController($this->container);
|
||||||
$controllerObject->notFound($e->hasLayout());
|
$controllerObject->notFound($e->hasLayout());
|
||||||
|
|||||||
@@ -16,6 +16,18 @@ class Response extends Base
|
|||||||
private $httpStatusCode = 200;
|
private $httpStatusCode = 200;
|
||||||
private $httpHeaders = array();
|
private $httpHeaders = array();
|
||||||
private $httpBody = '';
|
private $httpBody = '';
|
||||||
|
private $responseSent = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return true if the response have been sent to the user agent
|
||||||
|
*
|
||||||
|
* @access public
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function isResponseAlreadySent()
|
||||||
|
{
|
||||||
|
return $this->responseSent;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set HTTP status code
|
* Set HTTP status code
|
||||||
@@ -187,6 +199,8 @@ class Response extends Base
|
|||||||
*/
|
*/
|
||||||
public function send()
|
public function send()
|
||||||
{
|
{
|
||||||
|
$this->responseSent = true;
|
||||||
|
|
||||||
if ($this->httpStatusCode !== 200) {
|
if ($this->httpStatusCode !== 200) {
|
||||||
header('Status: '.$this->httpStatusCode);
|
header('Status: '.$this->httpStatusCode);
|
||||||
header($this->request->getServerVariable('SERVER_PROTOCOL').' '.$this->httpStatusCode);
|
header($this->request->getServerVariable('SERVER_PROTOCOL').' '.$this->httpStatusCode);
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ class BootstrapMiddleware extends BaseMiddleware
|
|||||||
$this->response->withContentSecurityPolicy($this->container['cspRules']);
|
$this->response->withContentSecurityPolicy($this->container['cspRules']);
|
||||||
$this->response->withSecurityHeaders();
|
$this->response->withSecurityHeaders();
|
||||||
|
|
||||||
if (ENABLE_XFRAME && $this->router->getAction() !== 'readonly') {
|
if (ENABLE_XFRAME) {
|
||||||
$this->response->withXframe();
|
$this->response->withXframe();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user