diff --git a/lib/Cake/Network/Request.php b/lib/Cake/Network/Request.php index 901d451fb5b..1be86fa08d5 100644 --- a/lib/Cake/Network/Request.php +++ b/lib/Cake/Network/Request.php @@ -69,7 +69,7 @@ class Request implements \ArrayAccess { * * @var string */ - public $base = false; + public $base; /** * webroot path segment for the request. @@ -83,7 +83,7 @@ class Request implements \ArrayAccess { * * @var string */ - public $here = null; + public $here; /** * Whether or not to trust HTTP_X headers set by most load balancers. @@ -298,14 +298,11 @@ protected static function _url($config) { * @return array Base URL, webroot dir ending in / */ protected static function _base() { - $dir = $webroot = null; + $base = $dir = $webroot = null; $config = Configure::read('App'); extract($config); - if (!isset($base)) { - $base = $this->base; - } - if ($base !== false) { + if ($base !== false && $base !== null) { return array($base, $base . '/'); } @@ -677,6 +674,9 @@ public function port() { * @return string The scheme used for the request. */ public function scheme() { + if ($this->trustProxy && env('HTTP_X_FORWARDED_PROTO')) { + return env('HTTP_X_FORWARDED_PROTO'); + } return env('HTTPS') ? 'https' : 'http'; } diff --git a/lib/Cake/Test/TestCase/Network/RequestTest.php b/lib/Cake/Test/TestCase/Network/RequestTest.php index fc0fbc49181..bdaaeb74e0d 100644 --- a/lib/Cake/Test/TestCase/Network/RequestTest.php +++ b/lib/Cake/Test/TestCase/Network/RequestTest.php @@ -649,11 +649,14 @@ public function testDomain() { public function testScheme() { $_SERVER['HTTPS'] = 'on'; $request = new Request(); - $this->assertEquals('https', $request->scheme()); unset($_SERVER['HTTPS']); $this->assertEquals('http', $request->scheme()); + + $_SERVER['HTTP_X_FORWARDED_PROTO'] = 'https'; + $request->trustProxy = true; + $this->assertEquals('https', $request->scheme()); } /**