2012-06-15 10:07:31 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Copyright (c) 2012 Bart Visscher <bartv@thisnet.nl>
|
|
|
|
* This file is licensed under the Affero General Public License version 3 or
|
|
|
|
* later.
|
|
|
|
* See the COPYING-README file.
|
|
|
|
*/
|
|
|
|
|
|
|
|
class OC_Request {
|
2012-08-06 20:16:45 +00:00
|
|
|
/**
|
|
|
|
* @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() {
|
2012-09-07 13:22:01 +00:00
|
|
|
if(OC::$CLI) {
|
2012-08-06 20:16:45 +00:00
|
|
|
return 'localhost';
|
|
|
|
}
|
2012-11-22 18:22:00 +00:00
|
|
|
if(OC_Config::getValue('overwritehost', '')<>''){
|
|
|
|
return OC_Config::getValue('overwritehost');
|
|
|
|
}
|
2012-08-06 20:16:45 +00:00
|
|
|
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() {
|
2012-11-22 18:22:00 +00:00
|
|
|
if(OC_Config::getValue('overwriteprotocol', '')<>''){
|
|
|
|
return OC_Config::getValue('overwriteprotocol');
|
|
|
|
}
|
2012-08-06 20:16:45 +00:00
|
|
|
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';
|
|
|
|
}
|
|
|
|
}
|
2012-09-04 06:18:28 +00:00
|
|
|
return $proto;
|
2012-08-06 20:16:45 +00:00
|
|
|
}
|
|
|
|
|
2012-08-07 18:33:25 +00:00
|
|
|
/**
|
|
|
|
* @brief get Path info from request
|
|
|
|
* @returns string Path info or false when not found
|
|
|
|
*/
|
|
|
|
public static function getPathInfo() {
|
2012-09-07 13:22:01 +00:00
|
|
|
if (array_key_exists('PATH_INFO', $_SERVER)) {
|
2012-08-07 18:33:25 +00:00
|
|
|
$path_info = $_SERVER['PATH_INFO'];
|
|
|
|
}else{
|
|
|
|
$path_info = substr($_SERVER['REQUEST_URI'], strlen($_SERVER['SCRIPT_NAME']));
|
2012-08-07 18:42:54 +00:00
|
|
|
// following is taken from Sabre_DAV_URLUtil::decodePathSegment
|
|
|
|
$path_info = rawurldecode($path_info);
|
2012-11-04 10:10:46 +00:00
|
|
|
$encoding = mb_detect_encoding($path_info, array('UTF-8', 'ISO-8859-1'));
|
2012-08-07 18:42:54 +00:00
|
|
|
|
|
|
|
switch($encoding) {
|
|
|
|
|
|
|
|
case 'ISO-8859-1' :
|
|
|
|
$path_info = utf8_encode($path_info);
|
|
|
|
|
|
|
|
}
|
|
|
|
// end copy
|
2012-08-07 18:33:25 +00:00
|
|
|
}
|
|
|
|
return $path_info;
|
|
|
|
}
|
|
|
|
|
2012-08-06 20:17:10 +00:00
|
|
|
/**
|
|
|
|
* @brief Check if this is a no-cache request
|
|
|
|
* @returns true for no-cache
|
|
|
|
*/
|
2012-06-15 10:07:31 +00:00
|
|
|
static public function isNoCache() {
|
|
|
|
if (!isset($_SERVER['HTTP_CACHE_CONTROL'])) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return $_SERVER['HTTP_CACHE_CONTROL'] == 'no-cache';
|
|
|
|
}
|
|
|
|
|
2012-08-06 20:17:10 +00:00
|
|
|
/**
|
|
|
|
* @brief Check if the requestor understands gzip
|
|
|
|
* @returns true for gzip encoding supported
|
|
|
|
*/
|
2012-06-15 10:07:31 +00:00
|
|
|
static public function acceptGZip() {
|
2012-06-18 09:33:24 +00:00
|
|
|
if (!isset($_SERVER['HTTP_ACCEPT_ENCODING'])) {
|
|
|
|
return false;
|
|
|
|
}
|
2012-06-15 10:07:31 +00:00
|
|
|
$HTTP_ACCEPT_ENCODING = $_SERVER["HTTP_ACCEPT_ENCODING"];
|
|
|
|
if( strpos($HTTP_ACCEPT_ENCODING, 'x-gzip') !== false )
|
|
|
|
return 'x-gzip';
|
2012-11-04 10:10:46 +00:00
|
|
|
else if( strpos($HTTP_ACCEPT_ENCODING, 'gzip') !== false )
|
2012-06-15 10:07:31 +00:00
|
|
|
return 'gzip';
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|