From a0070d8bf4b9e6cc51a34fa25bd978fb2665b6d6 Mon Sep 17 00:00:00 2001 From: epriestley Date: Sun, 30 Sep 2012 21:19:35 -0700 Subject: [PATCH] Make AphrontRequest::getHost() work properly in the presence of a port Summary: This currently gives us back "domain.com:port" if there's a port, which messes up the new Phame logic. Make `getHost()` do what one would reasonably expect it to. Test Plan: Loaded my local, which is on 8080. Reviewers: btrahan Reviewed By: btrahan CC: aran Differential Revision: https://secure.phabricator.com/D3571 --- src/aphront/AphrontRequest.php | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/aphront/AphrontRequest.php b/src/aphront/AphrontRequest.php index b35662c460..d2ce62f792 100644 --- a/src/aphront/AphrontRequest.php +++ b/src/aphront/AphrontRequest.php @@ -60,7 +60,10 @@ final class AphrontRequest { } final public function getHost() { - return $this->host; + // The "Host" header may include a port number; if so, ignore it. We can't + // use PhutilURI since there's no URI scheme. + list($actual_host) = explode(':', $this->host, 2); + return $actual_host; } @@ -272,13 +275,12 @@ final class AphrontRequest { $base_domain = $base_uri->getDomain(); $base_protocol = $base_uri->getProtocol(); - // The "Host" header may include a port number; if so, ignore it. We can't - // use PhutilURI since there's no URI scheme. - list($actual_host) = explode(':', $this->getHost(), 2); - if ($base_domain != $actual_host) { + $host = $this->getHost(); + + if ($base_domain != $host) { throw new Exception( "This install of Phabricator is configured as '{$base_domain}' but ". - "you are accessing it via '{$actual_host}'. Access Phabricator via ". + "you are accessing it via '{$host}'. Access Phabricator via ". "the primary configured domain."); }