From f5219d24816c8b55aa757d37b7215905f3ee7073 Mon Sep 17 00:00:00 2001 From: Carsten Brandt Date: Wed, 20 Nov 2013 14:14:04 +0100 Subject: [PATCH] Response status code default is 200 fixes #1220 --- framework/yii/web/Response.php | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/framework/yii/web/Response.php b/framework/yii/web/Response.php index 8934fa1..1d77d14 100644 --- a/framework/yii/web/Response.php +++ b/framework/yii/web/Response.php @@ -126,9 +126,10 @@ class Response extends \yii\base\Response */ public $charset; /** - * @var string + * @var string the HTTP status description that comes together with the status code. + * @see [[httpStatuses]] */ - public $statusText; + public $statusText = 'OK'; /** * @var string the version of the HTTP protocol to use. If not set, it will be determined via `$_SERVER['SERVER_PROTOCOL']`, * or '1.1' if that is not available. @@ -208,7 +209,7 @@ class Response extends \yii\base\Response /** * @var integer the HTTP status code to send with the response. */ - private $_statusCode; + private $_statusCode = 200; /** * @var HeaderCollection */ @@ -248,11 +249,6 @@ class Response extends \yii\base\Response */ public function setStatusCode($value, $text = null) { - if ($value === null) { - $this->_statusCode = null; - $this->statusText = null; - return; - } $this->_statusCode = (int)$value; if ($this->getIsInvalid()) { throw new InvalidParamException("The HTTP status code is invalid: $value"); @@ -297,10 +293,10 @@ class Response extends \yii\base\Response { $this->_headers = null; $this->_cookies = null; - $this->_statusCode = null; + $this->_statusCode = 200; + $this->statusText = 'OK'; $this->data = null; $this->content = null; - $this->statusText = null; } /** @@ -312,9 +308,7 @@ class Response extends \yii\base\Response return; } $statusCode = $this->getStatusCode(); - if ($statusCode !== null) { - header("HTTP/{$this->version} $statusCode {$this->statusText}"); - } + header("HTTP/{$this->version} $statusCode {$this->statusText}"); if ($this->_headers) { $headers = $this->getHeaders(); foreach ($headers as $name => $values) {