@@ -73,8 +73,10 @@ class SiteURI extends URI
7373 /**
7474 * @param string $relativePath URI path relative to baseURL. May include
7575 * queries or fragments.
76+ * @param string $host Hostname. If it is not in $allowedHostnames,
77+ * just be ignored.
7678 */
77- public function __construct (App $ configApp , string $ relativePath = '' )
79+ public function __construct (App $ configApp , string $ relativePath = '' , string $ host = '' )
7880 {
7981 $ this ->baseURL = $ this ->normalizeBaseURL ($ configApp );
8082 $ this ->indexPage = $ configApp ->indexPage ;
@@ -97,21 +99,33 @@ public function __construct(App $configApp, string $relativePath = '')
9799 $ tempUri = $ this ->baseURL . $ indexPage . $ relativePath ;
98100 $ uri = new URI ($ tempUri );
99101
102+ // Update scheme
100103 if ($ configApp ->forceGlobalSecureRequests ) {
101104 $ uri ->setScheme ('https ' );
102105 }
103106
107+ // Update host
108+ if ($ host !== '' && $ this ->checkHost ($ host , $ configApp ->allowedHostnames )) {
109+ $ uri ->setHost ($ host );
110+ }
111+
104112 $ parts = parse_url ((string ) $ uri );
105113 if ($ parts === false ) {
106114 throw HTTPException::forUnableToParseURI ($ uri );
107115 }
108116 $ this ->applyParts ($ parts );
109117
118+ // Set routePath
110119 $ parts = explode ('? ' , $ relativePath );
111120 $ routePath = $ parts [0 ];
112121 $ this ->setRoutePath ($ routePath );
113122 }
114123
124+ private function checkHost (string $ host , array $ allowedHostnames ): bool
125+ {
126+ return in_array ($ host , $ allowedHostnames , true );
127+ }
128+
115129 private function normalizeBaseURL (App $ configApp ): string
116130 {
117131 // It's possible the user forgot a trailing slash on their
0 commit comments