Response should only be sent once.

pull/87/head
Mike Cao 11 years ago
parent b8026d9828
commit 6a1029a187

@ -29,6 +29,11 @@ class Response {
*/
protected $body;
/**
* @var bool If a response has already been sent
*/
protected static $sent = false;
/**
* @var array HTTP status codes
*/
@ -169,7 +174,6 @@ class Response {
* @return object Self reference
*/
public function sendHeaders() {
if (!headers_sent()) {
// Send status code header
if (strpos(php_sapi_name(), 'cgi') !== false) {
header(
@ -204,7 +208,6 @@ class Response {
header($field.': '.$value);
}
}
}
return $this;
}
@ -219,10 +222,16 @@ class Response {
ob_end_clean();
}
if (!self::$sent) {
if (!headers_sent()) {
$this->sendHeaders();
}
echo $this->body;
self::$sent = true;
}
return $this;
}
}

Loading…
Cancel
Save