Updating env(HTTPS); to more accurately reflect the PHP $_SERVER docs. Fixes #6524

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@8246 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
mark_story 2009-07-22 13:40:12 +00:00
parent d6a12ce5f1
commit 7ca85109cb
2 changed files with 19 additions and 2 deletions

View file

@ -362,8 +362,8 @@ if (!function_exists('array_combine')) {
*/
function env($key) {
if ($key == 'HTTPS') {
if (isset($_SERVER) && !empty($_SERVER)) {
return (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on');
if (isset($_SERVER['HTTPS'])) {
return (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off');
}
return (strpos(env('SCRIPT_URI'), 'https://') === 0);
}

View file

@ -94,12 +94,29 @@ class BasicsTest extends CakeTestCase {
$_SERVER = $_ENV = array();
$this->assertFalse(env('HTTPS'));
$_SERVER['HTTPS'] = 'on';
$this->assertTrue(env('HTTPS'));
$_SERVER['HTTPS'] = '1';
$this->assertTrue(env('HTTPS'));
$_SERVER['HTTPS'] = 'I am not empty';
$this->assertTrue(env('HTTPS'));
$_SERVER['HTTPS'] = 1;
$this->assertTrue(env('HTTPS'));
$_SERVER['HTTPS'] = 'off';
$this->assertFalse(env('HTTPS'));
$_SERVER['HTTPS'] = false;
$this->assertFalse(env('HTTPS'));
$_SERVER['HTTPS'] = '';
$this->assertFalse(env('HTTPS'));
$_SERVER = array();
$_ENV['SCRIPT_URI'] = 'https://domain.test/a/test.php';