Commit f5219d24 by Carsten Brandt

Response status code default is 200

fixes #1220
parent 2d5f4e56
...@@ -126,9 +126,10 @@ class Response extends \yii\base\Response ...@@ -126,9 +126,10 @@ class Response extends \yii\base\Response
*/ */
public $charset; 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']`, * @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. * or '1.1' if that is not available.
...@@ -208,7 +209,7 @@ class Response extends \yii\base\Response ...@@ -208,7 +209,7 @@ class Response extends \yii\base\Response
/** /**
* @var integer the HTTP status code to send with the response. * @var integer the HTTP status code to send with the response.
*/ */
private $_statusCode; private $_statusCode = 200;
/** /**
* @var HeaderCollection * @var HeaderCollection
*/ */
...@@ -248,11 +249,6 @@ class Response extends \yii\base\Response ...@@ -248,11 +249,6 @@ class Response extends \yii\base\Response
*/ */
public function setStatusCode($value, $text = null) public function setStatusCode($value, $text = null)
{ {
if ($value === null) {
$this->_statusCode = null;
$this->statusText = null;
return;
}
$this->_statusCode = (int)$value; $this->_statusCode = (int)$value;
if ($this->getIsInvalid()) { if ($this->getIsInvalid()) {
throw new InvalidParamException("The HTTP status code is invalid: $value"); throw new InvalidParamException("The HTTP status code is invalid: $value");
...@@ -297,10 +293,10 @@ class Response extends \yii\base\Response ...@@ -297,10 +293,10 @@ class Response extends \yii\base\Response
{ {
$this->_headers = null; $this->_headers = null;
$this->_cookies = null; $this->_cookies = null;
$this->_statusCode = null; $this->_statusCode = 200;
$this->statusText = 'OK';
$this->data = null; $this->data = null;
$this->content = null; $this->content = null;
$this->statusText = null;
} }
/** /**
...@@ -312,9 +308,7 @@ class Response extends \yii\base\Response ...@@ -312,9 +308,7 @@ class Response extends \yii\base\Response
return; return;
} }
$statusCode = $this->getStatusCode(); $statusCode = $this->getStatusCode();
if ($statusCode !== null) {
header("HTTP/{$this->version} $statusCode {$this->statusText}"); header("HTTP/{$this->version} $statusCode {$this->statusText}");
}
if ($this->_headers) { if ($this->_headers) {
$headers = $this->getHeaders(); $headers = $this->getHeaders();
foreach ($headers as $name => $values) { foreach ($headers as $name => $values) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment