Skip to content

Commit

Permalink
removed the non-standard Client-IP HTTP header
Browse files Browse the repository at this point in the history
  • Loading branch information
fabpot committed Nov 29, 2012
1 parent fc89d6b commit 254b110
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 16 deletions.
4 changes: 1 addition & 3 deletions src/Symfony/Component/HttpFoundation/Request.php
Expand Up @@ -450,9 +450,7 @@ public function setSession(Session $session)
public function getClientIp($proxy = false)
{
if ($proxy) {
if ($this->server->has('HTTP_CLIENT_IP')) {
return $this->server->get('HTTP_CLIENT_IP');
} elseif (self::$trustProxy && $this->server->has('HTTP_X_FORWARDED_FOR')) {
if (self::$trustProxy && $this->server->has('HTTP_X_FORWARDED_FOR')) {
$clientIp = explode(',', $this->server->get('HTTP_X_FORWARDED_FOR'), 2);

return isset($clientIp[0]) ? trim($clientIp[0]) : '';
Expand Down
21 changes: 8 additions & 13 deletions tests/Symfony/Tests/Component/HttpFoundation/RequestTest.php
Expand Up @@ -496,16 +496,13 @@ public function testGetSetMethod()
/**
* @dataProvider testGetClientIpProvider
*/
public function testGetClientIp($expected, $proxy, $remoteAddr, $httpClientIp, $httpForwardedFor)
public function testGetClientIp($expected, $proxy, $remoteAddr, $httpForwardedFor)
{
$request = new Request;
$this->assertEquals('', $request->getClientIp());
$this->assertEquals('', $request->getClientIp(true));

$server = array('REMOTE_ADDR' => $remoteAddr);
if (null !== $httpClientIp) {
$server['HTTP_CLIENT_IP'] = $httpClientIp;
}
if (null !== $httpForwardedFor) {
$server['HTTP_X_FORWARDED_FOR'] = $httpForwardedFor;
}
Expand All @@ -517,15 +514,13 @@ public function testGetClientIp($expected, $proxy, $remoteAddr, $httpClientIp, $
public function testGetClientIpProvider()
{
return array(
array('88.88.88.88', false, '88.88.88.88', null, null),
array('127.0.0.1', false, '127.0.0.1', '88.88.88.88', null),
array('88.88.88.88', true, '127.0.0.1', '88.88.88.88', null),
array('127.0.0.1', false, '127.0.0.1', null, '88.88.88.88'),
array('88.88.88.88', true, '127.0.0.1', null, '88.88.88.88'),
array('::1', false, '::1', null, null),
array('2620:0:1cfe:face:b00c::3', true, '::1', '2620:0:1cfe:face:b00c::3', null),
array('2620:0:1cfe:face:b00c::3', true, '::1', null, '2620:0:1cfe:face:b00c::3, ::1'),
array('88.88.88.88', true, '123.45.67.89', null, '88.88.88.88, 87.65.43.21, 127.0.0.1'),
array('88.88.88.88', false, '88.88.88.88', null),
array('127.0.0.1', false, '127.0.0.1', null),
array('127.0.0.1', false, '127.0.0.1', '88.88.88.88'),
array('88.88.88.88', true, '127.0.0.1', '88.88.88.88'),
array('::1', false, '::1', null),
array('2620:0:1cfe:face:b00c::3', true, '::1', '2620:0:1cfe:face:b00c::3, ::1'),
array('88.88.88.88', true, '123.45.67.89', '88.88.88.88, 87.65.43.21, 127.0.0.1'),
);
}

Expand Down

0 comments on commit 254b110

Please sign in to comment.