mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Fix casing issues with Authorization header.
We need to check the upper case versions of headers in $_SERVER. Also fix lint issues.
This commit is contained in:
parent
345375b6b6
commit
20a2af8c16
2 changed files with 8 additions and 7 deletions
|
@ -748,12 +748,13 @@ class CakeRequest implements ArrayAccess {
|
||||||
* @return mixed Either false on no header being set or the value of the header.
|
* @return mixed Either false on no header being set or the value of the header.
|
||||||
*/
|
*/
|
||||||
public static function header($name) {
|
public static function header($name) {
|
||||||
$http_name = 'HTTP_' . strtoupper(str_replace('-', '_', $name));
|
$name = strtoupper(str_replace('-', '_', $name));
|
||||||
if (isset($_SERVER[$http_name])) {
|
$httpName = 'HTTP_' . $name;
|
||||||
return $_SERVER[$http_name];
|
if (isset($_SERVER[$httpName])) {
|
||||||
|
return $_SERVER[$httpName];
|
||||||
}
|
}
|
||||||
// Work around Apache issue handling the "Authorization" header
|
// Work around Apache issues where 'Authorization' is not
|
||||||
// differently than other headers.
|
// passed to PHP.
|
||||||
if (isset($_SERVER[$name])) {
|
if (isset($_SERVER[$name])) {
|
||||||
return $_SERVER[$name];
|
return $_SERVER[$name];
|
||||||
}
|
}
|
||||||
|
|
|
@ -1147,13 +1147,13 @@ class CakeRequestTest extends CakeTestCase {
|
||||||
$_SERVER['HTTP_X_THING'] = '';
|
$_SERVER['HTTP_X_THING'] = '';
|
||||||
$_SERVER['HTTP_HOST'] = 'localhost';
|
$_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';
|
$_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';
|
||||||
$_SERVER['ThatOneHeader'] = 'foobar';
|
$_SERVER['AUTHORIZATION'] = 'foobar';
|
||||||
$request = new CakeRequest('/', false);
|
$request = new CakeRequest('/', false);
|
||||||
|
|
||||||
$this->assertEquals($_SERVER['HTTP_HOST'], $request->header('host'));
|
$this->assertEquals($_SERVER['HTTP_HOST'], $request->header('host'));
|
||||||
$this->assertEquals($_SERVER['HTTP_USER_AGENT'], $request->header('User-Agent'));
|
$this->assertEquals($_SERVER['HTTP_USER_AGENT'], $request->header('User-Agent'));
|
||||||
$this->assertSame('', $request->header('X-thing'));
|
$this->assertSame('', $request->header('X-thing'));
|
||||||
$this->assertEquals($_SERVER['ThatOneHeader'], $request->header('ThatOneHeader'));
|
$this->assertEquals($_SERVER['AUTHORIZATION'], $request->header('Authorization'));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in a new issue