Visitar URL original
Update request URI scheme with config value · phpmyadmin/phpmyadmin@fd88454 · GitHub
Skip to content

Commit fd88454

Browse files
committed
Update request URI scheme with config value
Removes the Config::isHttps() call from constructor as PmaAbsoluteUri is not available yet. Signed-off-by: Maurício Meneghini Fauth <mauricio@fauth.dev>
1 parent 74ba4f1 commit fd88454

2 files changed

Lines changed: 19 additions & 8 deletions

File tree

‎libraries/classes/Common.php‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,8 @@ public static function run(bool $isSetupPage = false): void
119119
return;
120120
}
121121

122+
$request = self::updateUriScheme($config, $request);
123+
122124
if ($route !== '/messages') {
123125
try {
124126
// Include session handling after the globals, to prevent overwriting.
@@ -647,4 +649,15 @@ private static function getGenericError(string $message): string
647649
'error_message' => $message,
648650
]);
649651
}
652+
653+
private static function updateUriScheme(Config $config, ServerRequest $request): ServerRequest
654+
{
655+
$uriScheme = $config->isHttps() ? 'https' : 'http';
656+
$uri = $request->getUri();
657+
if ($uri->getScheme() === $uriScheme) {
658+
return $request;
659+
}
660+
661+
return $request->withUri($uri->withScheme($uriScheme));
662+
}
650663
}

‎libraries/classes/Config.php‎

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
use function ini_get;
3333
use function intval;
3434
use function is_array;
35+
use function is_bool;
3536
use function is_dir;
3637
use function is_int;
3738
use function is_numeric;
@@ -93,15 +94,10 @@ class Config
9394
/** @var mixed[] */
9495
public array $defaultServer = [];
9596

96-
private bool $isHttps;
97+
private bool $isHttps = false;
9798

9899
private Settings|null $config = null;
99100

100-
public function __construct()
101-
{
102-
$this->isHttps = $this->isHttps();
103-
}
104-
105101
/**
106102
* @param string|null $source source to read config from
107103
*
@@ -117,6 +113,7 @@ public function loadAndCheck(string|null $source = null): void
117113
// other settings, independent of config file, comes in
118114
$this->checkSystem();
119115

116+
$this->isHttps = $this->isHttps();
120117
$this->baseSettings = $this->settings;
121118
}
122119

@@ -783,9 +780,10 @@ public function checkUploadSize(): void
783780
*/
784781
public function isHttps(): bool
785782
{
783+
/** @var mixed $isHttps */
786784
$isHttps = $this->get('is_https');
787-
if ($isHttps !== null) {
788-
return (bool) $isHttps;
785+
if (is_bool($isHttps)) {
786+
return $isHttps;
789787
}
790788

791789
$url = $this->get('PmaAbsoluteUri');

0 commit comments

Comments
 (0)