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

Loading…
Cancel
Save