koel/app/Http/Middleware/ForceHttps.php

29 lines
611 B
PHP
Raw Normal View History

2019-05-18 20:43:30 +00:00
<?php
namespace App\Http\Middleware;
use Closure;
use Illuminate\Http\Request;
2019-08-05 10:56:48 +00:00
use Illuminate\Routing\UrlGenerator;
2020-12-22 20:11:22 +00:00
use Symfony\Component\HttpFoundation\Response;
2019-05-18 20:43:30 +00:00
class ForceHttps
{
2019-08-05 10:56:48 +00:00
private $url;
public function __construct(UrlGenerator $url)
{
$this->url = $url;
}
2020-12-22 20:11:22 +00:00
public function handle(Request $request, Closure $next): Response
2019-05-18 20:43:30 +00:00
{
if (config('koel.force_https')) {
2019-08-05 10:56:48 +00:00
$this->url->forceScheme('https');
2019-05-18 20:43:30 +00:00
$request->setTrustedProxies([$request->getClientIp()], Request::HEADER_X_FORWARDED_ALL);
}
return $next($request);
}
}