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;
|
2019-05-18 20:43:30 +00:00
|
|
|
|
|
|
|
class ForceHttps
|
|
|
|
{
|
2022-07-29 06:47:10 +00:00
|
|
|
public function __construct(private UrlGenerator $url)
|
2019-08-05 10:56:48 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2021-06-05 10:47:56 +00:00
|
|
|
public function handle(Request $request, Closure $next) // @phpcs:ignore
|
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');
|
2021-06-05 10:47:56 +00:00
|
|
|
$request->setTrustedProxies(
|
|
|
|
[$request->getClientIp()],
|
|
|
|
Request::HEADER_X_FORWARDED_FOR
|
|
|
|
| Request::HEADER_X_FORWARDED_HOST
|
|
|
|
| Request::HEADER_X_FORWARDED_PORT
|
|
|
|
| Request::HEADER_X_FORWARDED_PROTO
|
|
|
|
);
|
2019-05-18 20:43:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return $next($request);
|
|
|
|
}
|
|
|
|
}
|