Skip to content

Commit 2502606

Browse files
committed
detect also forwarded proto
1 parent 6edde5f commit 2502606

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

src/Config/BaseUrl.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,13 +67,11 @@ public function __toString(): string
6767

6868
private function autoDetectUrl(): string
6969
{
70-
$https = isset($_SERVER['HTTPS']) ? strtolower($_SERVER['HTTPS']) : null;
71-
$scheme = !empty($https) && $https != 'off' ? 'https' : 'http';
72-
$host = $_SERVER['HTTP_HOST'] ?? ($_SERVER['SERVER_NAME'] ?? 'localhost');
70+
$https = isset($_SERVER['HTTPS']) ? strtolower($_SERVER['HTTPS']) : null;
71+
$httpsForwarded = isset($_SERVER['HTTP_X_FORWARDED_PROTO']) ? strtolower($_SERVER['HTTP_X_FORWARDED_PROTO']) : null;
7372

74-
if (empty($host)) {
75-
throw new \RuntimeException('Could not detect hostname, please specify the url in your config');
76-
}
73+
$scheme = $https === 'on' || $httpsForwarded === 'https' ? 'https' : 'http';
74+
$host = $_SERVER['HTTP_HOST'] ?? ($_SERVER['SERVER_NAME'] ?? 'localhost');
7775

7876
return $scheme . '://' . $host;
7977
}

0 commit comments

Comments
 (0)