diff --git a/system/HTTP/SiteURI.php b/system/HTTP/SiteURI.php index 372d3939eb15..c9c8cc566519 100644 --- a/system/HTTP/SiteURI.php +++ b/system/HTTP/SiteURI.php @@ -73,10 +73,12 @@ class SiteURI extends URI /** * @param string $relativePath URI path relative to baseURL. May include * queries or fragments. - * @param string $host Hostname. If it is not in $allowedHostnames, + * @param string $host Optional hostname. If it is not in $allowedHostnames, * just be ignored. + * @param string $scheme Optional scheme. 'http' or 'https'. + * @phpstan-param 'http'|'https'|'' $scheme */ - public function __construct(App $configApp, string $relativePath = '', string $host = '') + public function __construct(App $configApp, string $relativePath = '', string $host = '', string $scheme = '') { $this->baseURL = $this->normalizeBaseURL($configApp); $this->indexPage = $configApp->indexPage; @@ -100,7 +102,9 @@ public function __construct(App $configApp, string $relativePath = '', string $h $uri = new URI($tempUri); // Update scheme - if ($configApp->forceGlobalSecureRequests) { + if ($scheme !== '') { + $uri->setScheme($scheme); + } elseif ($configApp->forceGlobalSecureRequests) { $uri->setScheme('https'); } diff --git a/tests/system/HTTP/SiteURITest.php b/tests/system/HTTP/SiteURITest.php index 413ab66ee57c..bdc6679bacc1 100644 --- a/tests/system/HTTP/SiteURITest.php +++ b/tests/system/HTTP/SiteURITest.php @@ -70,6 +70,16 @@ public function testConstructorHost() $this->assertSame('/index.php/', $uri->getPath()); } + public function testConstructorScheme() + { + $config = new App(); + + $uri = new SiteURI($config, '', '', 'https'); + + $this->assertInstanceOf(SiteURI::class, $uri); + $this->assertSame('https://example.com/index.php/', (string) $uri); + } + public function testConstructorSubfolder() { $config = new App();