From 27a9390ec7da68dcb05c7cd5d0e06eb9ae9f2913 Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Thu, 31 May 2018 14:05:33 -0600 Subject: [PATCH] Re-added SSL off-loading that was lost with Grav v1.4.0 merge #1888 --- CHANGELOG.md | 7 +++++++ system/src/Grav/Common/Uri.php | 19 ++++++++++++++++--- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 156ee48c0..37362128f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,10 @@ +# v1.4.6 +## mm/dd/2018 + +1. [](#improved) + * Manually re-added the improved SSL off-loading that was lost with Grav v1.4.0 merge [#1888](https://github.com/getgrav/grav/pull/1888) + + # v1.4.5 ## 05/15/2018 diff --git a/system/src/Grav/Common/Uri.php b/system/src/Grav/Common/Uri.php index 412a3abd5..06546665b 100644 --- a/system/src/Grav/Common/Uri.php +++ b/system/src/Grav/Common/Uri.php @@ -1119,8 +1119,12 @@ class Uri protected function createFromEnvironment(array $env) { // Build scheme. - if (isset($env['REQUEST_SCHEME'])) { - $this->scheme = $env['REQUEST_SCHEME']; + if (isset($env['HTTP_X_FORWARDED_PROTO'])) { + $this->scheme = $env['HTTP_X_FORWARDED_PROTO']; + } elseif (isset($env['X-FORWARDED-PROTO'])) { + $this->scheme = $env['X-FORWARDED-PROTO']; + } elseif (isset($env['REQUEST_SCHEME'])) { + $this->scheme = $env['REQUEST_SCHEME']; } else { $https = isset($env['HTTPS']) ? $env['HTTPS'] : ''; $this->scheme = (empty($https) || strtolower($https) === 'off') ? 'http' : 'https'; @@ -1143,7 +1147,16 @@ class Uri $this->host = $this->validateHostname($hostname) ? $hostname : 'unknown'; // Build port. - $this->port = isset($env['SERVER_PORT']) ? (int)$env['SERVER_PORT'] : null; + if (isset($env['HTTP_X_FORWARDED_PORT'])) { + $this->port = (int)$env['HTTP_X_FORWARDED_PORT']; + } elseif (isset($env['X-FORWARDED-PORT'])) { + $this->port = (int)$env['X-FORWARDED-PORT']; + } elseif (isset($env['SERVER_PORT'])) { + $this->port = (int)$env['SERVER_PORT']; + } else { + $this->port = null; + } + if ($this->hasStandardPort()) { $this->port = null; }