@@ -218,13 +218,20 @@ class RouteCollection implements RouteCollectionInterface
218218 */
219219 protected $ prioritizeDetected = false ;
220220
221+ /**
222+ * The current hostname from $_SERVER['HTTP_HOST']
223+ */
224+ private ?string $ httpHost = null ;
225+
221226 /**
222227 * Constructor
223228 */
224229 public function __construct (FileLocator $ locator , Modules $ moduleConfig )
225230 {
226231 $ this ->fileLocator = $ locator ;
227232 $ this ->moduleConfig = $ moduleConfig ;
233+
234+ $ this ->httpHost = Services::request ()->getServer ('HTTP_HOST ' );
228235 }
229236
230237 /**
@@ -1176,7 +1183,7 @@ protected function create(string $verb, string $from, $to, ?array $options = nul
11761183 // Hostname limiting?
11771184 if (! empty ($ options ['hostname ' ])) {
11781185 // @todo determine if there's a way to whitelist hosts?
1179- if (isset ($ _SERVER [ ' HTTP_HOST ' ] ) && strtolower ($ _SERVER [ ' HTTP_HOST ' ] ) !== strtolower ($ options ['hostname ' ])) {
1186+ if (isset ($ this -> httpHost ) && strtolower ($ this -> httpHost ) !== strtolower ($ options ['hostname ' ])) {
11801187 return ;
11811188 }
11821189
@@ -1302,7 +1309,7 @@ private function getMethodParams(string $from): string
13021309 private function checkSubdomains ($ subdomains ): bool
13031310 {
13041311 // CLI calls can't be on subdomain.
1305- if (! isset ($ _SERVER [ ' HTTP_HOST ' ] )) {
1312+ if (! isset ($ this -> httpHost )) {
13061313 return false ;
13071314 }
13081315
@@ -1337,7 +1344,7 @@ private function determineCurrentSubdomain()
13371344 // We have to ensure that a scheme exists
13381345 // on the URL else parse_url will mis-interpret
13391346 // 'host' as the 'path'.
1340- $ url = $ _SERVER [ ' HTTP_HOST ' ] ;
1347+ $ url = $ this -> httpHost ;
13411348 if (strpos ($ url , 'http ' ) !== 0 ) {
13421349 $ url = 'http:// ' . $ url ;
13431350 }
0 commit comments