diff options
Diffstat (limited to 'src/Http')
-rw-r--r-- | src/Http/RequestServiceProvider.php | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/src/Http/RequestServiceProvider.php b/src/Http/RequestServiceProvider.php index 077e9ecc..bbf2579c 100644 --- a/src/Http/RequestServiceProvider.php +++ b/src/Http/RequestServiceProvider.php @@ -8,7 +8,34 @@ class RequestServiceProvider extends ServiceProvider { public function register() { + $config = $this->app->get('config'); + $trustedProxies = $config->get('trusted_proxies', []); + + if (!is_array($trustedProxies)) { + $trustedProxies = empty($trustedProxies) ? [] : explode(',', preg_replace('~\s+~', '', $trustedProxies)); + } + + /** @var Request $request */ $request = $this->app->call([Request::class, 'createFromGlobals']); + $this->setTrustedProxies($request, $trustedProxies); $this->app->instance('request', $request); } + + /** + * Set the trusted Proxies + * + * Required for unit tests (static methods can't be mocked) + * + * @param Request $request + * @param array $proxies + * @param int $trustedHeadersSet + * @codeCoverageIgnore + */ + protected function setTrustedProxies( + $request, + $proxies, + $trustedHeadersSet = Request::HEADER_FORWARDED | Request::HEADER_X_FORWARDED_ALL + ) { + $request->setTrustedProxies($proxies, $trustedHeadersSet); + } } |