Browse Source

Response status code default is 200

fixes #1220
tags/2.0.0-beta
Carsten Brandt 11 years ago
parent
commit
f5219d2481
  1. 20
      framework/yii/web/Response.php

20
framework/yii/web/Response.php

@ -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
/** /**
* @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
*/ */
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
{ {
$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
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) {

Loading…
Cancel
Save