Allow empty headers to be read.

Allow headers with '' and '0' as their values to be read.

Fixes #6299
This commit is contained in:
mark_story 2015-04-08 16:33:28 -04:00
parent b2958dad79
commit f55111bdc1
2 changed files with 3 additions and 1 deletions

View file

@ -648,7 +648,7 @@ class CakeRequest implements ArrayAccess {
*/
public static function header($name) {
$name = 'HTTP_' . strtoupper(str_replace('-', '_', $name));
if (!empty($_SERVER[$name])) {
if (isset($_SERVER[$name])) {
return $_SERVER[$name];
}
return false;

View file

@ -1069,12 +1069,14 @@ class CakeRequestTest extends CakeTestCase {
* @return void
*/
public function testHeader() {
$_SERVER['HTTP_X_THING'] = '';
$_SERVER['HTTP_HOST'] = 'localhost';
$_SERVER['HTTP_USER_AGENT'] = 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_4; en-ca) AppleWebKit/534.8+ (KHTML, like Gecko) Version/5.0 Safari/533.16';
$request = new CakeRequest('/', false);
$this->assertEquals($_SERVER['HTTP_HOST'], $request->header('host'));
$this->assertEquals($_SERVER['HTTP_USER_AGENT'], $request->header('User-Agent'));
$this->assertSame('', $request->header('X-thing'));
}
/**