Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 9033e91

Browse files
[HttpFoundation] µ-optimize Request::setTrustedProxies()
1 parent 1958d21 commit 9033e91

File tree

1 file changed

+6
-10
lines changed

1 file changed

+6
-10
lines changed

src/Symfony/Component/HttpFoundation/Request.php

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -520,20 +520,16 @@ public function overrideGlobals(): void
520520
*
521521
* You should only list the reverse proxies that you manage directly.
522522
*
523-
* @param array $proxies A list of trusted proxies, the string 'REMOTE_ADDR' will be replaced with $_SERVER['REMOTE_ADDR']
524-
* @param int $trustedHeaderSet A bit field of Request::HEADER_*, to set which headers to trust from your proxies
523+
* @param array $proxies A list of trusted proxies, the string 'REMOTE_ADDR' will be replaced with $_SERVER['REMOTE_ADDR']
524+
* @param int-mask-of<Request::HEADER_*> $trustedHeaderSet A bit field to set which headers to trust from your proxies
525525
*/
526526
public static function setTrustedProxies(array $proxies, int $trustedHeaderSet): void
527527
{
528-
self::$trustedProxies = array_reduce($proxies, function ($proxies, $proxy) {
529-
if ('REMOTE_ADDR' !== $proxy) {
530-
$proxies[] = $proxy;
531-
} elseif (isset($_SERVER['REMOTE_ADDR'])) {
532-
$proxies[] = $_SERVER['REMOTE_ADDR'];
533-
}
528+
if (isset($_SERVER['REMOTE_ADDR']) && false !== $i = array_search('REMOTE_ADDR', $proxies, true)) {
529+
$proxies[$i] = $_SERVER['REMOTE_ADDR'];
530+
}
534531

535-
return $proxies;
536-
}, []);
532+
self::$trustedProxies = $proxies;
537533
self::$trustedHeaderSet = $trustedHeaderSet;
538534
}
539535

0 commit comments

Comments
 (0)