diff options
| author | 2022-06-21 10:46:50 +0200 | |
|---|---|---|
| committer | 2022-06-21 10:46:50 +0200 | |
| commit | 47ab9d5e77dc2949ad3d0b9be779f2cbb17652e8 (patch) | |
| tree | 63d9ac9ee8bf80f6d5ea820746491c5c37b955d8 /lib/Minz/Request.php | |
| parent | 5b31c8212f5c12300d06b345915ca6fd2c1c16f9 (diff) | |
Better trim base_url (#4423)
Avoid usual errors for instance with quotes, especially when provided through Docker / CLI
Diffstat (limited to 'lib/Minz/Request.php')
| -rw-r--r-- | lib/Minz/Request.php | 37 |
1 files changed, 9 insertions, 28 deletions
diff --git a/lib/Minz/Request.php b/lib/Minz/Request.php index d67e23fdf..9179eb368 100644 --- a/lib/Minz/Request.php +++ b/lib/Minz/Request.php @@ -133,10 +133,8 @@ class Minz_Request { /** * Return true if the request is over HTTPS, false otherwise (HTTP) - * - * @return boolean */ - public static function isHttps() { + public static function isHttps(): bool { $header = $_SERVER['HTTP_X_FORWARDED_PROTO'] ?? ''; if ('' != $header) { return 'https' === strtolower($header); @@ -159,10 +157,7 @@ class Minz_Request { return filter_var("{$protocol}://{$host}{$port}{$prefix}{$path}", FILTER_SANITIZE_URL); } - /** - * @return string - */ - private static function extractProtocol() { + private static function extractProtocol(): string { if (self::isHttps()) { return 'https'; } @@ -202,10 +197,7 @@ class Minz_Request { return self::isHttps() ? 443 : 80; } - /** - * @return string - */ - private static function extractPortForUrl() { + private static function extractPortForUrl(): string { if (self::isHttps() && 443 !== $port = self::extractPort()) { return ":{$port}"; } @@ -215,10 +207,7 @@ class Minz_Request { return ''; } - /** - * @return string - */ - private static function extractPrefix() { + private static function extractPrefix(): string { if ('' != $prefix = ($_SERVER['HTTP_X_FORWARDED_PREFIX'] ?? '')) { return rtrim($prefix, '/ '); } @@ -235,13 +224,11 @@ class Minz_Request { } /** - * Return the base_url from configuration and add a suffix if given. - * - * @return string base_url with a suffix. + * Return the base_url from configuration */ - public static function getBaseUrl() { + public static function getBaseUrl(): string { $conf = Minz_Configuration::get('system'); - $url = rtrim($conf->base_url, '/\\'); + $url = trim($conf->base_url, ' /\\"'); return filter_var($url, FILTER_SANITIZE_URL); } @@ -397,17 +384,11 @@ class Minz_Request { } } - /** - * @return string - */ - private static function extractContentType() { + private static function extractContentType(): string { return strtolower(trim($_SERVER['CONTENT_TYPE'] ?? '')); } - /** - * @return boolean - */ - public static function isPost() { + public static function isPost(): bool { return 'POST' === ($_SERVER['REQUEST_METHOD'] ?? ''); } |
