Skip to content

Commit

Permalink
Fixing style errors.
Browse files Browse the repository at this point in the history
  • Loading branch information
stickler-ci committed Jun 13, 2018
1 parent 28f27f3 commit 7d9d7e7
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 16 deletions.
16 changes: 3 additions & 13 deletions src/Http/ServerRequest.php
Expand Up @@ -127,7 +127,7 @@ class ServerRequest implements ArrayAccess, ServerRequestInterface

/**
* trusted proxies list
*
*
* @var array
*/
protected $trustedProxies = [];
Expand Down Expand Up @@ -585,39 +585,29 @@ public function session(Session $session = null)
public function clientIp()
{
if ($this->trustProxy) {

if ($forwarded = $this->getEnv('HTTP_X_FORWARDED_FOR')) {

$addresses = array_map('trim', explode(',', $forwarded));
$trusted = (count($this->trustedProxies) > 0);
$n = count($addresses);

if ($trusted) {

for ($i = 1; $i < $n; $i++)
{
for ($i = 1; $i < $n; $i++) {
if (in_array($addresses[$i], $this->trustedProxies) === false) {

$trusted = false;
break;
}
}
}

return (($trusted) ? $addresses[0] : $addresses[$n - 1]);

} else {

if ($ip = $this->getEnv('HTTP_X_REAL_IP')) {

return $ip;

} elseif ($ip = $this->getEnv('HTTP_CLIENT_IP')) {

return $ip;
}
}
}
}

return $this->getEnv('REMOTE_ADDR');
}
Expand Down
6 changes: 3 additions & 3 deletions tests/TestCase/Http/ServerRequestTest.php
Expand Up @@ -741,7 +741,7 @@ public function testClientIp()

/**
* test clientIp method with trusted proxies
*
*
* @return void
*/
public function testClientIpWithTrustedProxies()
Expand All @@ -753,7 +753,6 @@ public function testClientIpWithTrustedProxies()
'REMOTE_ADDR' => '192.168.1.4',
]]);


$request->setTrustedProxies([
'192.168.1.0',
'192.168.1.1',
Expand All @@ -763,7 +762,8 @@ public function testClientIpWithTrustedProxies()

$this->assertEquals('real.ip', $request->clientIp());

$request = $request->withEnv('HTTP_X_FORWARDED_FOR',
$request = $request->withEnv(
'HTTP_X_FORWARDED_FOR',
'spoof.fake.ip, real.ip, 192.168.1.0, 192.168.1.2, 192.168.1.3'
);
$this->assertEquals('192.168.1.3', $request->clientIp());
Expand Down

0 comments on commit 7d9d7e7

Please sign in to comment.