[HttpKernel] optimized previous merge
This commit is contained in:
parent
2f3b33a630
commit
e03e2cd0fa
@ -90,13 +90,10 @@ class InlineFragmentRenderer extends RoutableFragmentRenderer
|
|||||||
// Sub-request object will point to localhost as client ip and real client ip
|
// Sub-request object will point to localhost as client ip and real client ip
|
||||||
// will be included into trusted header for client ip
|
// will be included into trusted header for client ip
|
||||||
try {
|
try {
|
||||||
$headerClientIp = 'HTTP_' . Request::getTrustedHeaderName(Request::HEADER_CLIENT_IP);
|
$trustedHeaderName = Request::getTrustedHeaderName(Request::HEADER_CLIENT_IP);
|
||||||
|
$currentXForwardedFor = $request->headers->get($trustedHeaderName, '');
|
||||||
|
|
||||||
$originalXForwardedFor = isset($server[$headerClientIp])
|
$server['HTTP_'.$trustedHeaderName] = ($currentXForwardedFor ? $currentXForwardedFor.', ' : '').$request->getClientIp();
|
||||||
? $server[$headerClientIp] . ', '
|
|
||||||
: '';
|
|
||||||
|
|
||||||
$server[$headerClientIp] = $originalXForwardedFor . $server['REMOTE_ADDR'];
|
|
||||||
} catch (\InvalidArgumentException $e) {
|
} catch (\InvalidArgumentException $e) {
|
||||||
// Do nothing
|
// Do nothing
|
||||||
}
|
}
|
||||||
|
@ -55,12 +55,8 @@ class InlineFragmentRendererTest extends \PHPUnit_Framework_TestCase
|
|||||||
'_format' => 'html',
|
'_format' => 'html',
|
||||||
'_controller' => 'main_controller',
|
'_controller' => 'main_controller',
|
||||||
));
|
));
|
||||||
$subRequest->headers->add(array(
|
$subRequest->headers->set('x-forwarded-for', array('127.0.0.1'));
|
||||||
'x-forwarded-for' => array('127.0.0.1'),
|
$subRequest->server->set('HTTP_X_FORWARDED_FOR', '127.0.0.1');
|
||||||
));
|
|
||||||
$subRequest->server->add(array(
|
|
||||||
'HTTP_X_FORWARDED_FOR' => '127.0.0.1',
|
|
||||||
));
|
|
||||||
|
|
||||||
$kernel = $this->getMock('Symfony\Component\HttpKernel\HttpKernelInterface');
|
$kernel = $this->getMock('Symfony\Component\HttpKernel\HttpKernelInterface');
|
||||||
$kernel
|
$kernel
|
||||||
@ -148,6 +144,8 @@ class InlineFragmentRendererTest extends \PHPUnit_Framework_TestCase
|
|||||||
{
|
{
|
||||||
$expectedSubRequest = Request::create('/');
|
$expectedSubRequest = Request::create('/');
|
||||||
$expectedSubRequest->headers->set('Surrogate-Capability', 'abc="ESI/1.0"');
|
$expectedSubRequest->headers->set('Surrogate-Capability', 'abc="ESI/1.0"');
|
||||||
|
$expectedSubRequest->headers->set('x-forwarded-for', array('127.0.0.1'));
|
||||||
|
$expectedSubRequest->server->set('HTTP_X_FORWARDED_FOR', '127.0.0.1');
|
||||||
|
|
||||||
$kernel = $this->getMock('Symfony\Component\HttpKernel\HttpKernelInterface');
|
$kernel = $this->getMock('Symfony\Component\HttpKernel\HttpKernelInterface');
|
||||||
$kernel
|
$kernel
|
||||||
|
Reference in New Issue
Block a user