From 481dcac2cc1a616a7f398d86665f6e4bb8ef6ffc Mon Sep 17 00:00:00 2001 From: Leonid Nikitin Date: Wed, 24 Apr 2024 20:53:59 +0500 Subject: [PATCH] Fixed an error when the APP_FORCE_HTTPS=true parameter is set, and nginx sends the http scheme. --- .../app/Http/Middleware/ProjectDomainAndLanguage.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/app/application/app/Http/Middleware/ProjectDomainAndLanguage.php b/app/application/app/Http/Middleware/ProjectDomainAndLanguage.php index 6503c95..99d6236 100644 --- a/app/application/app/Http/Middleware/ProjectDomainAndLanguage.php +++ b/app/application/app/Http/Middleware/ProjectDomainAndLanguage.php @@ -5,6 +5,7 @@ use App\Enums\CacheTag; use Closure; use Illuminate\Http\Request; +use Illuminate\Support\Str; use Symfony\Component\HttpFoundation\Response; final class ProjectDomainAndLanguage extends ProjectLanguage @@ -12,6 +13,12 @@ final class ProjectDomainAndLanguage extends ProjectLanguage public function handle(Request $request, Closure $next): Response { $httpHost = $request->getSchemeAndHttpHost(); + if ( + config('app.force_https') === true + && Str::startsWith($httpHost, 'http://') + ) { + $httpHost = Str::of($httpHost)->replaceFirst('http://', 'https://')->toString(); + } $seconds = 3600; $project = CacheTag::Project->getCache()->remember(self::class . $httpHost, $seconds, function () use ($httpHost) {