From e66c3d4a9e7951e64eafd853c9f7e116776a450c Mon Sep 17 00:00:00 2001 From: Witold Wasiczko Date: Tue, 24 Feb 2015 14:08:27 +0100 Subject: [PATCH] Add support for non 443 port --- src/Helper/ServerUrl.php | 11 ++++++++++- test/Helper/ServerUrlTest.php | 1 + 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/Helper/ServerUrl.php b/src/Helper/ServerUrl.php index ef338561..cf076f5c 100644 --- a/src/Helper/ServerUrl.php +++ b/src/Helper/ServerUrl.php @@ -112,6 +112,10 @@ protected function detectPort() } if (isset($_SERVER['SERVER_PORT']) && $_SERVER['SERVER_PORT']) { + if ($this->isReversedProxy()) { + $this->setPort(443); + return; + } $this->setPort($_SERVER['SERVER_PORT']); return; } @@ -132,7 +136,7 @@ protected function detectScheme() case (isset($_SERVER['HTTPS']) && ($_SERVER['HTTPS'] == 'on' || $_SERVER['HTTPS'] === true)): case (isset($_SERVER['HTTP_SCHEME']) && ($_SERVER['HTTP_SCHEME'] == 'https')): case (443 === $this->getPort()): - case (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https'): + case $this->isReversedProxy(): $scheme = 'https'; break; default: @@ -143,6 +147,11 @@ protected function detectScheme() $this->setScheme($scheme); } + protected function isReversedProxy() + { + return isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https'; + } + /** * Detect if a proxy is in use, and, if so, set the host based on it * diff --git a/test/Helper/ServerUrlTest.php b/test/Helper/ServerUrlTest.php index 7caed56e..0f6cbb6a 100644 --- a/test/Helper/ServerUrlTest.php +++ b/test/Helper/ServerUrlTest.php @@ -91,6 +91,7 @@ public function testConstructorWithHostReversedProxyHttpsTrue() { $_SERVER['HTTP_HOST'] = 'example.com'; $_SERVER['HTTP_X_FORWARDED_PROTO'] = 'https'; + $_SERVER['SERVER_PORT'] = 80; $url = new Helper\ServerUrl(); $this->assertEquals('https://example.com', $url->__invoke());