diff options
author | Igor Scheller <igor.scheller@igorshp.de> | 2018-08-13 16:30:27 +0200 |
---|---|---|
committer | msquare <msquare@notrademark.de> | 2018-08-19 16:44:33 +0200 |
commit | bf6efe532c8f2de84e95b090911280a9b1b61ce8 (patch) | |
tree | 33f767dc22b8073e1151782b77d1a48b25ff28b0 /src/Http | |
parent | 6415882b1c3c9ead00ccbab09e2292a22ce3d1d2 (diff) |
Added trusted proxies
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); + } } |