removed the non-standard Client-IP HTTP header
This commit is contained in:
parent
fc89d6b643
commit
254b11062e
@ -450,9 +450,7 @@ class Request
|
||||
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]) : '';
|
||||
|
@ -496,16 +496,13 @@ class RequestTest extends \PHPUnit_Framework_TestCase
|
||||
/**
|
||||
* @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;
|
||||
}
|
||||
@ -517,15 +514,13 @@ class RequestTest extends \PHPUnit_Framework_TestCase
|
||||
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'),
|
||||
);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user