aboutsummaryrefslogtreecommitdiff
path: root/lib/Minz/Request.php
diff options
context:
space:
mode:
authorGravatar Marien Fressinaud <dev@marienfressinaud.fr> 2015-11-04 20:17:29 +0100
committerGravatar Marien Fressinaud <dev@marienfressinaud.fr> 2015-11-04 20:17:29 +0100
commita1267baa0b1caa801547ee674d9bb03c4b15d00b (patch)
tree78c5567578751752a3623574cbd768e602a46754 /lib/Minz/Request.php
parent133e369afff02e5984fe4ce5109e33fd2fbccfc7 (diff)
parent4525e547faa8781e37f86125110f28248eb67fd3 (diff)
Merge branch 'dev' into beta
Diffstat (limited to 'lib/Minz/Request.php')
-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..effb9943c 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);