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

Commit

Permalink
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/Helper/ServerUrl.php
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,15 @@ protected function detectHost()
}

if (isset($_SERVER['HTTP_HOST']) && !empty($_SERVER['HTTP_HOST'])) {
// Detect if the port is set in SERVER_PORT and included in HTTP_HOST
if (isset($_SERVER['SERVER_PORT'])) {
$portStr = ':' . $_SERVER['SERVER_PORT'];
if (substr($_SERVER['HTTP_HOST'], 0-strlen($portStr), strlen($portStr)) == $portStr) {
$this->setHost(substr($_SERVER['HTTP_HOST'], 0, 0-strlen($portStr)));
return;
}
}

$this->setHost($_SERVER['HTTP_HOST']);
return;
}
Expand Down
9 changes: 9 additions & 0 deletions test/Helper/ServerUrlTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,15 @@ public function testConstructorWithHostIncludingPortAndHttpsTrue()
$this->assertEquals('https://example.com:8181', $url->__invoke());
}

public function testConstructorWithHttpHostIncludingPortAndPortSet()
{
$_SERVER['HTTP_HOST'] = 'example.com:8181';
$_SERVER['SERVER_PORT'] = 8181;

$url = new Helper\ServerUrl();
$this->assertEquals('http://example.com:8181', $url->__invoke());
}

public function testConstructorWithHttpHostAndServerNameAndPortSet()
{
$_SERVER['HTTP_HOST'] = 'example.com';
Expand Down

0 comments on commit 098e166

Please sign in to comment.