Move serverHost and serverProtocol functions to OC_Request

This commit is contained in:
Bart Visscher 2012-08-06 22:16:45 +02:00
parent c4f1a1de5b
commit 99ce7ba1df
4 changed files with 50 additions and 51 deletions

View File

@ -185,8 +185,8 @@ class OC{
// redirect to https site if configured // redirect to https site if configured
if( OC_Config::getValue( "forcessl", false )){ if( OC_Config::getValue( "forcessl", false )){
ini_set("session.cookie_secure", "on"); ini_set("session.cookie_secure", "on");
if(OC_Helper::serverProtocol()<>'https' and !OC::$CLI) { if(OC_Request::serverProtocol()<>'https' and !OC::$CLI) {
$url = "https://". OC_Helper::serverHost() . $_SERVER['REQUEST_URI']; $url = "https://". OC_Request::serverHost() . $_SERVER['REQUEST_URI'];
header("Location: $url"); header("Location: $url");
exit(); exit();
} }

View File

@ -64,52 +64,6 @@ class OC_Helper {
return $urlLinkTo; return $urlLinkTo;
} }
/**
* @brief Returns the server host
* @returns the server host
*
* Returns the server host, even if the website uses one or more
* reverse proxies
*/
public static function serverHost() {
if(OC::$CLI){
return 'localhost';
}
if (isset($_SERVER['HTTP_X_FORWARDED_HOST'])) {
if (strpos($_SERVER['HTTP_X_FORWARDED_HOST'], ",") !== false) {
$host = trim(array_pop(explode(",", $_SERVER['HTTP_X_FORWARDED_HOST'])));
}
else{
$host=$_SERVER['HTTP_X_FORWARDED_HOST'];
}
}
else{
$host = $_SERVER['HTTP_HOST'];
}
return $host;
}
/**
* @brief Returns the server protocol
* @returns the server protocol
*
* Returns the server protocol. It respects reverse proxy servers and load balancers
*/
public static function serverProtocol() {
if (isset($_SERVER['HTTP_X_FORWARDED_PROTO'])) {
$proto = strtolower($_SERVER['HTTP_X_FORWARDED_PROTO']);
}else{
if(isset($_SERVER['HTTPS']) and !empty($_SERVER['HTTPS']) and ($_SERVER['HTTPS']!='off')) {
$proto = 'https';
}else{
$proto = 'http';
}
}
return($proto);
}
/** /**
* @brief Creates an absolute url * @brief Creates an absolute url
* @param $app app * @param $app app
@ -132,7 +86,7 @@ class OC_Helper {
*/ */
public static function makeURLAbsolute( $url ) public static function makeURLAbsolute( $url )
{ {
return self::serverProtocol(). '://' . self::serverHost() . $url; return OC_Request::serverProtocol(). '://' . OC_Request::serverHost() . $url;
} }
/** /**

View File

@ -165,7 +165,7 @@ class Util {
* reverse proxies * reverse proxies
*/ */
public static function getServerHost() { public static function getServerHost() {
return(\OC_Helper::serverHost()); return(\OC_Request::serverHost());
} }
/** /**
@ -175,7 +175,7 @@ class Util {
* Returns the server protocol. It respects reverse proxy servers and load balancers * Returns the server protocol. It respects reverse proxy servers and load balancers
*/ */
public static function getServerProtocol() { public static function getServerProtocol() {
return(\OC_Helper::serverProtocol()); return(\OC_Request::serverProtocol());
} }
/** /**

View File

@ -7,6 +7,51 @@
*/ */
class OC_Request { class OC_Request {
/**
* @brief Returns the server host
* @returns the server host
*
* Returns the server host, even if the website uses one or more
* reverse proxies
*/
public static function serverHost() {
if(OC::$CLI){
return 'localhost';
}
if (isset($_SERVER['HTTP_X_FORWARDED_HOST'])) {
if (strpos($_SERVER['HTTP_X_FORWARDED_HOST'], ",") !== false) {
$host = trim(array_pop(explode(",", $_SERVER['HTTP_X_FORWARDED_HOST'])));
}
else{
$host=$_SERVER['HTTP_X_FORWARDED_HOST'];
}
}
else{
$host = $_SERVER['HTTP_HOST'];
}
return $host;
}
/**
* @brief Returns the server protocol
* @returns the server protocol
*
* Returns the server protocol. It respects reverse proxy servers and load balancers
*/
public static function serverProtocol() {
if (isset($_SERVER['HTTP_X_FORWARDED_PROTO'])) {
$proto = strtolower($_SERVER['HTTP_X_FORWARDED_PROTO']);
}else{
if(isset($_SERVER['HTTPS']) and !empty($_SERVER['HTTPS']) and ($_SERVER['HTTPS']!='off')) {
$proto = 'https';
}else{
$proto = 'http';
}
}
return($proto);
}
static public function isNoCache() { static public function isNoCache() {
if (!isset($_SERVER['HTTP_CACHE_CONTROL'])) { if (!isset($_SERVER['HTTP_CACHE_CONTROL'])) {
return false; return false;