Details
-
Type:
Improvement
-
Status:
Resolved
-
Priority:
Trivial
-
Resolution: Fixed
-
Affects Version/s: None
-
Fix Version/s: 1.6.1
-
Component/s: Zend_Controller
-
Labels:None
Description
The current method definition:
/**
* Validate HTTP status redirect code
*
* @param int $code
* @throws Zend_Controller_Action_Exception on invalid HTTP status code
* @return true
*/
protected function _checkCode($code)
{
$code = (int)$code;
if ((300 > $code) || (307 < $code)) {
/**
* @see Zend_Controller_Exception
*/
require_once 'Zend/Controller/Exception.php';
throw new Zend_Controller_Action_Exception('Invalid redirect HTTP status code (' . $code . ')');
}
return true;
}
Propose 1: Change the method to accept string, a HTTP code is not an integer, string is the correct type to use.
Propose 2: Be more correct about the accepted codes: Currently the method accepts invalid redirect codes.
From the HTTP/1.1 RFC (http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html):
- 307 Temporary Redirect - Valid
- 306 (Unused) - Invalid
- 305 Use Proxy - Valid
- 304 Not Modified - Invalid (not a redirect)
- 303 See Other - Valid
- 302 Found - Valid
- 301 Moved Permanently - Valid
- 300 Multiple Choices - Valid
Improved class proposal:
/**
* HTTP status code for redirects
* @var string
*/
protected $_code = '302';
...
/**
* Validate HTTP status redirect code
*
* @param string $code
* @throws Zend_Controller_Action_Exception on invalid HTTP status code
* @return true
*/
protected function _checkCode($code)
{
$code = (string)$code;
if (false === in_array($code, array('300', '301', '302', '303', '305', '307'))) {
/**
* @see Zend_Controller_Exception
*/
require_once 'Zend/Controller/Exception.php';
throw new Zend_Controller_Action_Exception('Invalid redirect HTTP status code (' . $code . ')');
}
return true;
}
/**
* Retrieve HTTP status code for {@link _redirect()} behaviour
*
* @param string $code
* @return Zend_Controller_Action_Helper_Redirector Provides a fluent interface
*/
public function setCode($code)
{
$this->_checkCode($code);
$this->_code = $code;
return $this;
}
Doc may be influenced.