Skip to content

Commit

Permalink
bug #22873 [HttpKernel] don't call getTrustedHeaderName() if possible…
Browse files Browse the repository at this point in the history
… (xabbuh)

This PR was merged into the 3.3 branch.

Discussion
----------

[HttpKernel] don't call getTrustedHeaderName() if possible

| Q             | A
| ------------- | ---
| Branch?       | 3.3
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | https://travis-ci.org/symfony/symfony/jobs/235008102 (failing tests of #22863)
| License       | MIT
| Doc PR        |

Commits
-------

6350dab don't call getTrustedHeaderName() if possible
  • Loading branch information
nicolas-grekas committed May 25, 2017
2 parents 2642e72 + 6350dab commit 4e95aac
Showing 1 changed file with 5 additions and 1 deletion.
Expand Up @@ -119,7 +119,11 @@ protected function createSubRequest($uri, Request $request)
// Sub-request object will point to localhost as client ip and real client ip
// will be included into trusted header for client ip
try {
if ($trustedHeaderName = Request::getTrustedHeaderName(Request::HEADER_CLIENT_IP, false)) {
if (Request::HEADER_X_FORWARDED_FOR & Request::getTrustedHeaderSet()) {
$currentXForwardedFor = $request->headers->get('X_FORWARDED_FOR', '');

$server['HTTP_X_FORWARDED_FOR'] = ($currentXForwardedFor ? $currentXForwardedFor.', ' : '').$request->getClientIp();
} elseif (method_exists(Request::class, 'getTrustedHeaderName') && $trustedHeaderName = Request::getTrustedHeaderName(Request::HEADER_CLIENT_IP, false)) {
$currentXForwardedFor = $request->headers->get($trustedHeaderName, '');

$server['HTTP_'.$trustedHeaderName] = ($currentXForwardedFor ? $currentXForwardedFor.', ' : '').$request->getClientIp();
Expand Down

0 comments on commit 4e95aac

Please sign in to comment.