diff --git a/lib/Cake/Network/CakeRequest.php b/lib/Cake/Network/CakeRequest.php index e48d3dcc5..f7f65d4f0 100644 --- a/lib/Cake/Network/CakeRequest.php +++ b/lib/Cake/Network/CakeRequest.php @@ -417,10 +417,6 @@ class CakeRequest implements ArrayAccess { */ public function referer($local = false) { $ref = env('HTTP_REFERER'); - $forwarded = env('HTTP_X_FORWARDED_HOST'); - if ($forwarded) { - $ref = $forwarded; - } $base = Configure::read('App.fullBaseUrl') . $this->webroot; if (!empty($ref) && !empty($base)) { @@ -667,9 +663,13 @@ class CakeRequest implements ArrayAccess { /** * Get the host that the request was handled on. * + * @param boolean $trustProxy Whether or not to trust the proxy host. * @return string */ - public function host() { + public function host($trustProxy = false) { + if ($trustProxy) { + return env('HTTP_X_FORWARDED_HOST'); + } return env('HTTP_HOST'); } diff --git a/lib/Cake/Test/Case/Network/CakeRequestTest.php b/lib/Cake/Test/Case/Network/CakeRequestTest.php index 471adf495..a433875e5 100644 --- a/lib/Cake/Test/Case/Network/CakeRequestTest.php +++ b/lib/Cake/Test/Case/Network/CakeRequestTest.php @@ -698,10 +698,6 @@ class CakeRequestTest extends CakeTestCase { $_SERVER['HTTP_REFERER'] = Configure::read('App.fullBaseUrl') . '/recipes/add'; $result = $request->referer(true); $this->assertSame($result, '/recipes/add'); - - $_SERVER['HTTP_X_FORWARDED_HOST'] = 'cakephp.org'; - $result = $request->referer(); - $this->assertSame($result, 'cakephp.org'); } /** @@ -804,9 +800,11 @@ class CakeRequestTest extends CakeTestCase { */ public function testHost() { $_SERVER['HTTP_HOST'] = 'localhost'; + $_SERVER['HTTP_X_FORWARDED_HOST'] = 'cakephp.org'; $request = new CakeRequest('some/path'); $this->assertEquals('localhost', $request->host()); + $this->assertEquals('cakephp.org', $request->host(true)); } /**