Skip to content

Commit

Permalink
Do not execute controller if the response is already sent
Browse files Browse the repository at this point in the history
  • Loading branch information
fguillot committed May 26, 2016
1 parent 74a84a2 commit 872dc79
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
5 changes: 4 additions & 1 deletion app/Core/Controller/Runner.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ public function execute()
{
try {
$this->executeMiddleware();
$this->executeController();

if (!$this->response->isResponseAlreadySent()) {
$this->executeController();
}
} catch (PageNotFoundException $e) {
$controllerObject = new AppController($this->container);
$controllerObject->notFound($e->hasLayout());
Expand Down
14 changes: 14 additions & 0 deletions app/Core/Http/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,18 @@ class Response extends Base
private $httpStatusCode = 200;
private $httpHeaders = array();
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
Expand Down Expand Up @@ -187,6 +199,8 @@ public function withFileDownload($filename)
*/
public function send()
{
$this->responseSent = true;

if ($this->httpStatusCode !== 200) {
header('Status: '.$this->httpStatusCode);
header($this->request->getServerVariable('SERVER_PROTOCOL').' '.$this->httpStatusCode);
Expand Down
2 changes: 1 addition & 1 deletion app/Middleware/BootstrapMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ private function sendHeaders()
$this->response->withContentSecurityPolicy($this->container['cspRules']);
$this->response->withSecurityHeaders();

if (ENABLE_XFRAME && $this->router->getAction() !== 'readonly') {
if (ENABLE_XFRAME) {
$this->response->withXframe();
}

Expand Down

0 comments on commit 872dc79

Please sign in to comment.