Skip to content
This repository has been archived by the owner on Jan 31, 2020. It is now read-only.

Commit

Permalink
Merge branch 'hotfix/zf2-508'
Browse files Browse the repository at this point in the history
Conflicts:
	README.md
  • Loading branch information
weierophinney committed Aug 31, 2012
2 parents 7d231f0 + a1fbb6f commit b61d89d
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/Helper/ServerUrl.php
Expand Up @@ -50,7 +50,14 @@ public function __construct()
}
$this->setScheme($scheme);

if (isset($_SERVER['HTTP_HOST']) && !empty($_SERVER['HTTP_HOST'])) {
if (isset($_SERVER['HTTP_X_FORWARDED_HOST']) && !empty($_SERVER['HTTP_X_FORWARDED_HOST'])) {
$host = $_SERVER['HTTP_X_FORWARDED_HOST'];
if (strpos($host, ',') !== false) {
$hosts = explode(',', $host);
$host = trim(array_pop($hosts));
}
$this->setHost($host);
} elseif (isset($_SERVER['HTTP_HOST']) && !empty($_SERVER['HTTP_HOST'])) {
$this->setHost($_SERVER['HTTP_HOST']);
} elseif (isset($_SERVER['SERVER_NAME'], $_SERVER['SERVER_PORT'])) {
$name = $_SERVER['SERVER_NAME'];
Expand Down
22 changes: 22 additions & 0 deletions test/Helper/ServerUrlTest.php
Expand Up @@ -161,4 +161,26 @@ public function testServerUrlWithPort()
$url = new Helper\ServerUrl();
$this->assertEquals('https://example.com', $url->__invoke());
}

/**
* @group ZF2-508
*/
public function testServerUrlWithProxy()
{
$_SERVER['HTTP_HOST'] = 'proxyserver.com';
$_SERVER['HTTP_X_FORWARDED_HOST'] = 'www.firsthost.org';
$url = new Helper\ServerUrl();
$this->assertEquals('http://www.firsthost.org', $url->__invoke());
}

/**
* @group ZF2-508
*/
public function testServerUrlWithMultipleProxies()
{
$_SERVER['HTTP_HOST'] = 'proxyserver.com';
$_SERVER['HTTP_X_FORWARDED_HOST'] = 'www.firsthost.org, www.secondhost.org';
$url = new Helper\ServerUrl();
$this->assertEquals('http://www.secondhost.org', $url->__invoke());
}
}

0 comments on commit b61d89d

Please sign in to comment.