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>
This commit is contained in:
Maurício Meneghini Fauth 2023-04-27 16:40:29 -03:00
parent 74ba4f17b0
commit fd88454d08
No known key found for this signature in database
GPG Key ID: 6A16FD38AFC89CC8
2 changed files with 19 additions and 8 deletions

View File

@ -119,6 +119,8 @@ final class Common
return;
}
$request = self::updateUriScheme($config, $request);
if ($route !== '/messages') {
try {
// Include session handling after the globals, to prevent overwriting.
@ -647,4 +649,15 @@ final class Common
'error_message' => $message,
]);
}
private static function updateUriScheme(Config $config, ServerRequest $request): ServerRequest
{
$uriScheme = $config->isHttps() ? 'https' : 'http';
$uri = $request->getUri();
if ($uri->getScheme() === $uriScheme) {
return $request;
}
return $request->withUri($uri->withScheme($uriScheme));
}
}

View File

@ -32,6 +32,7 @@ use function implode;
use function ini_get;
use function intval;
use function is_array;
use function is_bool;
use function is_dir;
use function is_int;
use function is_numeric;
@ -93,15 +94,10 @@ class Config
/** @var mixed[] */
public array $defaultServer = [];
private bool $isHttps;
private bool $isHttps = false;
private Settings|null $config = null;
public function __construct()
{
$this->isHttps = $this->isHttps();
}
/**
* @param string|null $source source to read config from
*
@ -117,6 +113,7 @@ class Config
// other settings, independent of config file, comes in
$this->checkSystem();
$this->isHttps = $this->isHttps();
$this->baseSettings = $this->settings;
}
@ -783,9 +780,10 @@ class Config
*/
public function isHttps(): bool
{
/** @var mixed $isHttps */
$isHttps = $this->get('is_https');
if ($isHttps !== null) {
return (bool) $isHttps;
if (is_bool($isHttps)) {
return $isHttps;
}
$url = $this->get('PmaAbsoluteUri');