aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Alexandre Alapetite <alexandre@alapetite.fr> 2015-10-25 01:38:19 +0200
committerGravatar Alexandre Alapetite <alexandre@alapetite.fr> 2015-10-25 01:38:19 +0200
commit9abd742fbc7bbbd3475b13dce8ac54057f25f970 (patch)
tree3eb83352a9967a7e8119d15f865e8c597fa0a782
parent46d72252013dd048be751ca9979b0836e32a3eb8 (diff)
parent30de13cd47a38f17608bfe0fe73d85979ec35fc2 (diff)
Merge branch 'baseUrl' into dev
-rw-r--r--lib/Minz/Request.php27
1 files changed, 24 insertions, 3 deletions
diff --git a/lib/Minz/Request.php b/lib/Minz/Request.php
index bf01bc26f..1c8efaf7b 100644
--- a/lib/Minz/Request.php
+++ b/lib/Minz/Request.php
@@ -91,9 +91,30 @@ class Minz_Request {
*/
public static function guessBaseUrl() {
$url = 'http';
- $host = empty($_SERVER['HTTP_HOST']) ? $_SERVER['SERVER_NAME'] : $_SERVER['HTTP_HOST'];
- $port = empty($_SERVER['SERVER_PORT']) ? 80 : $_SERVER['SERVER_PORT'];
- if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on') {
+
+ if (isset($_SERVER['HTTP_X_FORWARDED_PROTO'])) {
+ $https = strtolower($_SERVER['HTTP_X_FORWARDED_PROTO']) === 'https';
+ } else {
+ $https = isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on';
+ }
+
+ if (!empty($_SERVER['HTTP_HOST'])) {
+ $host = $_SERVER['HTTP_HOST'];
+ } elseif (!empty($_SERVER['SERVER_NAME'])) {
+ $host = $_SERVER['SERVER_NAME'];
+ } else {
+ $host = 'localhost';
+ }
+
+ if (!empty($_SERVER['HTTP_X_FORWARDED_PORT'])) {
+ $port = intval($_SERVER['HTTP_X_FORWARDED_PORT']);
+ } elseif (!empty($_SERVER['SERVER_PORT'])) {
+ $port = intval($_SERVER['SERVER_PORT']);
+ } else {
+ $port = $https ? 443 : 80;
+ }
+
+ if ($https) {
$url .= 's://' . $host . ($port == 443 ? '' : ':' . $port);
} else {
$url .= '://' . $host . ($port == 80 ? '' : ':' . $port);