Skip to content

Commit

Permalink
Merge pull request #95 from l0gicgate/FixBugInUriFactory
Browse files Browse the repository at this point in the history
Fix UriFactory Host Detection Logic
  • Loading branch information
l0gicgate committed May 6, 2019
2 parents ac5c29b + c89323d commit bd3737b
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/Factory/UriFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,15 @@ public function createFromGlobals(array $globals): Uri
$password = isset($globals['PHP_AUTH_PW']) ? $globals['PHP_AUTH_PW'] : '';

// Authority: Host
$host = '';
if (isset($globals['HTTP_HOST'])) {
$host = $globals['HTTP_HOST'] ?: '';
} else {
$host = $globals['SERVER_NAME'] ?: '';
$host = $globals['HTTP_HOST'];
} elseif (isset($globals['SERVER_NAME'])) {
$host = $globals['SERVER_NAME'];
}

// Authority: Port
$port = isset($globals['SERVER_PORT']) && !empty($globals['SERVER_PORT']) ? (int) $globals['SERVER_PORT'] : 80;
$port = !empty($globals['SERVER_PORT']) ? (int) $globals['SERVER_PORT'] : 80;
if (preg_match('/^(\[[a-fA-F0-9:.]+\])(:\d+)?\z/', $host, $matches)) {
$host = $matches[1];

Expand Down

0 comments on commit bd3737b

Please sign in to comment.