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
|
|
|
|
{
|
2019-08-05 10:56:48 +00:00
|
|
|
private $url;
|
|
|
|
|
|
|
|
public function __construct(UrlGenerator $url)
|
|
|
|
{
|
|
|
|
$this->url = $url;
|
|
|
|
}
|
|
|
|
|
2020-12-22 23:01:49 +00:00
|
|
|
/** @return mixed */
|
|
|
|
public function handle(Request $request, Closure $next)
|
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);
|
|
|
|
}
|
|
|
|
}
|