removed the non-standard Client-IP HTTP header

This commit is contained in:
Fabien Potencier 2012-11-27 19:09:41 +01:00
parent fc89d6b643
commit 254b11062e
2 changed files with 9 additions and 16 deletions

View File

@ -450,9 +450,7 @@ class Request
public function getClientIp($proxy = false) public function getClientIp($proxy = false)
{ {
if ($proxy) { if ($proxy) {
if ($this->server->has('HTTP_CLIENT_IP')) { if (self::$trustProxy && $this->server->has('HTTP_X_FORWARDED_FOR')) {
return $this->server->get('HTTP_CLIENT_IP');
} elseif (self::$trustProxy && $this->server->has('HTTP_X_FORWARDED_FOR')) {
$clientIp = explode(',', $this->server->get('HTTP_X_FORWARDED_FOR'), 2); $clientIp = explode(',', $this->server->get('HTTP_X_FORWARDED_FOR'), 2);
return isset($clientIp[0]) ? trim($clientIp[0]) : ''; return isset($clientIp[0]) ? trim($clientIp[0]) : '';

View File

@ -496,16 +496,13 @@ class RequestTest extends \PHPUnit_Framework_TestCase
/** /**
* @dataProvider testGetClientIpProvider * @dataProvider testGetClientIpProvider
*/ */
public function testGetClientIp($expected, $proxy, $remoteAddr, $httpClientIp, $httpForwardedFor) public function testGetClientIp($expected, $proxy, $remoteAddr, $httpForwardedFor)
{ {
$request = new Request; $request = new Request;
$this->assertEquals('', $request->getClientIp()); $this->assertEquals('', $request->getClientIp());
$this->assertEquals('', $request->getClientIp(true)); $this->assertEquals('', $request->getClientIp(true));
$server = array('REMOTE_ADDR' => $remoteAddr); $server = array('REMOTE_ADDR' => $remoteAddr);
if (null !== $httpClientIp) {
$server['HTTP_CLIENT_IP'] = $httpClientIp;
}
if (null !== $httpForwardedFor) { if (null !== $httpForwardedFor) {
$server['HTTP_X_FORWARDED_FOR'] = $httpForwardedFor; $server['HTTP_X_FORWARDED_FOR'] = $httpForwardedFor;
} }
@ -517,15 +514,13 @@ class RequestTest extends \PHPUnit_Framework_TestCase
public function testGetClientIpProvider() public function testGetClientIpProvider()
{ {
return array( return array(
array('88.88.88.88', false, '88.88.88.88', null, null), array('88.88.88.88', false, '88.88.88.88', null),
array('127.0.0.1', false, '127.0.0.1', '88.88.88.88', null), array('127.0.0.1', false, '127.0.0.1', 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', '88.88.88.88'),
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', '88.88.88.88'),
array('88.88.88.88', true, '127.0.0.1', null, '88.88.88.88'), array('::1', false, '::1', null),
array('::1', false, '::1', null, null), array('2620:0:1cfe:face:b00c::3', true, '::1', '2620:0:1cfe:face:b00c::3, ::1'),
array('2620:0:1cfe:face:b00c::3', true, '::1', '2620:0:1cfe:face:b00c::3', null), array('88.88.88.88', true, '123.45.67.89', '88.88.88.88, 87.65.43.21, 127.0.0.1'),
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'),
); );
} }