Skip to content

Commit 697bac9

Browse files
committed
feature symfony#18197 Make Request::isFromTrustedProxy() public. (Peter Bex)
This PR was merged into the 3.1-dev branch. Discussion ---------- Make Request::isFromTrustedProxy() public. | Q | A | ------------- | --- | Branch | master | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | | License | MIT | Doc PR | When adding custom headers to your proxy (in our particular case, a `X-Base-Url` header, but it could be anything), it is necessary to be able to tell whether the request came from a trusted proxy or not. Unfortunately, currently the `isFromTrustedProxy()` method is private, which means you'll need to subclass `Request` and add your own *differently named* method just to be able to access this information. This functionality is pretty straightforward, and I don't see a reason to keep this method private so this a trivial pull request to make it public (and it adds a comment so it'll show up in the API docs with proper documentation). Commits ------- 286f64f Make Request::isFromTrustedProxy() public.
2 parents 3598105 + 286f64f commit 697bac9

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/Symfony/Component/HttpFoundation/Request.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1931,7 +1931,15 @@ private static function createRequestFromFactory(array $query = array(), array $
19311931
return new static($query, $request, $attributes, $cookies, $files, $server, $content);
19321932
}
19331933

1934-
private function isFromTrustedProxy()
1934+
/**
1935+
* Indicates whether this request originated from a trusted proxy.
1936+
*
1937+
* This can be useful to determine whether or not to trust the
1938+
* contents of a proxy-specific header.
1939+
*
1940+
* @return bool true if the request came from a trusted proxy, false otherwise
1941+
*/
1942+
public function isFromTrustedProxy()
19351943
{
19361944
return self::$trustedProxies && IpUtils::checkIp($this->server->get('REMOTE_ADDR'), self::$trustedProxies);
19371945
}

0 commit comments

Comments
 (0)