2017-11-19 23:56:06 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace BookStack\Http\Middleware;
|
|
|
|
|
2017-12-08 03:46:25 +08:00
|
|
|
use Closure;
|
2021-10-31 04:29:59 +08:00
|
|
|
use Illuminate\Http\Middleware\TrustProxies as Middleware;
|
2018-09-25 23:58:03 +08:00
|
|
|
use Illuminate\Http\Request;
|
2017-11-19 23:56:06 +08:00
|
|
|
|
|
|
|
class TrustProxies extends Middleware
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* The trusted proxies for this application.
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
protected $proxies;
|
|
|
|
|
|
|
|
/**
|
2019-09-07 05:14:39 +08:00
|
|
|
* The headers that should be used to detect proxies.
|
2017-11-19 23:56:06 +08:00
|
|
|
*
|
2019-09-07 05:14:39 +08:00
|
|
|
* @var int
|
2017-11-19 23:56:06 +08:00
|
|
|
*/
|
2021-10-31 04:29:59 +08:00
|
|
|
protected $headers = Request::HEADER_X_FORWARDED_FOR | Request::HEADER_X_FORWARDED_HOST | Request::HEADER_X_FORWARDED_PORT | Request::HEADER_X_FORWARDED_PROTO | Request::HEADER_X_FORWARDED_AWS_ELB;
|
2017-12-08 03:46:25 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle the request, Set the correct user-configured proxy information.
|
2021-06-26 23:23:15 +08:00
|
|
|
*
|
2017-12-08 03:46:25 +08:00
|
|
|
* @param Request $request
|
|
|
|
* @param Closure $next
|
2021-06-26 23:23:15 +08:00
|
|
|
*
|
2017-12-08 03:46:25 +08:00
|
|
|
* @return mixed
|
|
|
|
*/
|
2019-11-20 19:00:20 +08:00
|
|
|
public function handle(Request $request, Closure $next)
|
2017-12-08 03:46:25 +08:00
|
|
|
{
|
|
|
|
$setProxies = config('app.proxies');
|
|
|
|
if ($setProxies !== '**' && $setProxies !== '*' && $setProxies !== '') {
|
|
|
|
$setProxies = explode(',', $setProxies);
|
|
|
|
}
|
|
|
|
$this->proxies = $setProxies;
|
|
|
|
|
|
|
|
return parent::handle($request, $next);
|
|
|
|
}
|
2017-11-19 23:56:06 +08:00
|
|
|
}
|