Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Recognize default port for https sites, closes #1346
  • Loading branch information
ginatrapani committed Jun 7, 2012
1 parent 39294c4 commit d562b93
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
14 changes: 11 additions & 3 deletions tests/TestOfUtils.php
Expand Up @@ -236,20 +236,28 @@ public function testGetApplicationURL() {

//nonstandard port
$_SERVER['HTTPS'] = null;
$_SERVER['SERVER_PORT'] = 1003;
$_SERVER['SERVER_PORT'] = '1003';
$utils_url = Utils::getApplicationURL();
$expected_url = 'http://mytestthinkup:1003/my/path/to/thinkup/';
$this->assertEqual($utils_url, $expected_url);

//standard port 80
$_SERVER['HTTPS'] = null;
$_SERVER['SERVER_PORT'] = 80;
$_SERVER['SERVER_PORT'] = '80';
$utils_url = Utils::getApplicationURL();
$expected_url = 'http://mytestthinkup/my/path/to/thinkup/';
$this->assertEqual($utils_url, $expected_url);

//SSL standard port 443
$_SERVER['HTTPS'] = true;
$_SERVER['SERVER_PORT'] = '443';
$utils_url = Utils::getApplicationURL();
$expected_url = 'https://mytestthinkup/my/path/to/thinkup/';
$this->assertEqual($utils_url, $expected_url);

//no port set
$_SERVER['SERVER_PORT'] = '';
$_SERVER['HTTPS'] = null;
$_SERVER['SERVER_PORT'] = '80';
$utils_url = Utils::getApplicationURL();
$expected_url = 'http://mytestthinkup/my/path/to/thinkup/';
$this->assertEqual($utils_url, $expected_url);
Expand Down
11 changes: 9 additions & 2 deletions webapp/_lib/model/class.Utils.php
Expand Up @@ -304,8 +304,15 @@ public static function getApplicationURL($replace_localhost_with_ip = false) {
$server = ($server == 'localhost')?'127.0.0.1':$server;
}
$site_root_path = Config::getInstance()->getValue('site_root_path');
$port = (isset($_SERVER['SERVER_PORT']) && $_SERVER['SERVER_PORT'] != "" && $_SERVER['SERVER_PORT'] != "80"
&& $_SERVER['SERVER_PORT'] != 80) ? ':'.$_SERVER['SERVER_PORT']:'';
if (isset($_SERVER['SERVER_PORT']) && $_SERVER['SERVER_PORT'] != '80') { //non-standard port
if (isset($_SERVER['HTTPS']) && $_SERVER['SERVER_PORT'] == '443') { //account for standard https port
$port = '';
} else {
$port = ':'.$_SERVER['SERVER_PORT'];
}
} else {
$port = '';
}
return 'http'.(isset($_SERVER['HTTPS'])?'s':'').'://'.$server.$port.$site_root_path;
}

Expand Down

0 comments on commit d562b93

Please sign in to comment.