This commit is contained in:
parent
6a9c5102b2
commit
42d3c4c9ca
@ -413,6 +413,14 @@ class HttpCache implements HttpKernelInterface, TerminableInterface
|
|||||||
$subRequest->headers->remove('if_modified_since');
|
$subRequest->headers->remove('if_modified_since');
|
||||||
$subRequest->headers->remove('if_none_match');
|
$subRequest->headers->remove('if_none_match');
|
||||||
|
|
||||||
|
// modify the X-Forwarded-For header if needed
|
||||||
|
$forwardedFor = $subRequest->headers->get('X-Forwarded-For');
|
||||||
|
if ($forwardedFor) {
|
||||||
|
$subRequest->headers->set('X-Forwarded-For', $forwardedFor.', '.$subRequest->server->get('REMOTE_ADDR'));
|
||||||
|
} else {
|
||||||
|
$subRequest->headers->set('X-Forwarded-For', $subRequest->server->get('REMOTE_ADDR'));
|
||||||
|
}
|
||||||
|
|
||||||
// fix the client IP address by setting it to 127.0.0.1 as HttpCache
|
// fix the client IP address by setting it to 127.0.0.1 as HttpCache
|
||||||
// is always called from the same process as the backend.
|
// is always called from the same process as the backend.
|
||||||
$subRequest->server->set('REMOTE_ADDR', '127.0.0.1');
|
$subRequest->server->set('REMOTE_ADDR', '127.0.0.1');
|
||||||
|
@ -1042,4 +1042,28 @@ class HttpCacheTest extends HttpCacheTestCase
|
|||||||
|
|
||||||
$this->assertEquals('127.0.0.1', $this->kernel->getBackendRequest()->server->get('REMOTE_ADDR'));
|
$this->assertEquals('127.0.0.1', $this->kernel->getBackendRequest()->server->get('REMOTE_ADDR'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dataProvider getXForwardedForData
|
||||||
|
*/
|
||||||
|
public function testXForwarderForHeaderForForwardedRequests($xForwardedFor, $expected)
|
||||||
|
{
|
||||||
|
$this->setNextResponse();
|
||||||
|
$server = array('REMOTE_ADDR' => '10.0.0.1');
|
||||||
|
if (false !== $xForwardedFor) {
|
||||||
|
$server['HTTP_X_FORWARDED_FOR'] = $xForwardedFor;
|
||||||
|
}
|
||||||
|
$this->request('GET', '/', $server);
|
||||||
|
|
||||||
|
$this->assertEquals($expected, $this->kernel->getBackendRequest()->headers->get('X-Forwarded-For'));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getXForwardedForData()
|
||||||
|
{
|
||||||
|
return array(
|
||||||
|
array(false, '10.0.0.1'),
|
||||||
|
array('10.0.0.2', '10.0.0.2, 10.0.0.1'),
|
||||||
|
array('10.0.0.2, 10.0.0.3', '10.0.0.2, 10.0.0.3, 10.0.0.1'),
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user