fixed the IP address in HttpCache when calling the backend
This commit is contained in:
parent
e0637fa9b7
commit
6a9c5102b2
@ -413,6 +413,10 @@ class HttpCache implements HttpKernelInterface, TerminableInterface
|
||||
$subRequest->headers->remove('if_modified_since');
|
||||
$subRequest->headers->remove('if_none_match');
|
||||
|
||||
// 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.
|
||||
$subRequest->server->set('REMOTE_ADDR', '127.0.0.1');
|
||||
|
||||
$response = $this->forward($subRequest, $catch);
|
||||
|
||||
if ($this->isPrivateRequest($request) && !$response->headers->hasCacheControlDirective('public')) {
|
||||
|
@ -1034,4 +1034,12 @@ class HttpCacheTest extends HttpCacheTestCase
|
||||
$this->assertEquals('Hello World!', $this->response->getContent());
|
||||
$this->assertEquals(12, $this->response->headers->get('Content-Length'));
|
||||
}
|
||||
|
||||
public function testClientIpIsAlwaysLocalhostForForwardedRequests()
|
||||
{
|
||||
$this->setNextResponse();
|
||||
$this->request('GET', '/', array('REMOTE_ADDR' => '10.0.0.1'));
|
||||
|
||||
$this->assertEquals('127.0.0.1', $this->kernel->getBackendRequest()->server->get('REMOTE_ADDR'));
|
||||
}
|
||||
}
|
||||
|
@ -26,6 +26,7 @@ class TestHttpKernel extends HttpKernel implements ControllerResolverInterface
|
||||
protected $called;
|
||||
protected $customizer;
|
||||
protected $catch;
|
||||
protected $backendRequest;
|
||||
|
||||
public function __construct($body, $status, $headers, \Closure $customizer = null)
|
||||
{
|
||||
@ -39,9 +40,15 @@ class TestHttpKernel extends HttpKernel implements ControllerResolverInterface
|
||||
parent::__construct(new EventDispatcher(), $this);
|
||||
}
|
||||
|
||||
public function getBackendRequest()
|
||||
{
|
||||
return $this->backendRequest;
|
||||
}
|
||||
|
||||
public function handle(Request $request, $type = HttpKernelInterface::MASTER_REQUEST, $catch = false)
|
||||
{
|
||||
$this->catch = $catch;
|
||||
$this->backendRequest = $request;
|
||||
|
||||
return parent::handle($request, $type, $catch);
|
||||
}
|
||||
|
@ -25,6 +25,7 @@ class TestMultipleHttpKernel extends HttpKernel implements ControllerResolverInt
|
||||
protected $headers;
|
||||
protected $catch;
|
||||
protected $call;
|
||||
protected $backendRequest;
|
||||
|
||||
public function __construct($responses)
|
||||
{
|
||||
@ -42,8 +43,15 @@ class TestMultipleHttpKernel extends HttpKernel implements ControllerResolverInt
|
||||
parent::__construct(new EventDispatcher(), $this);
|
||||
}
|
||||
|
||||
public function getBackendRequest()
|
||||
{
|
||||
return $this->backendRequest;
|
||||
}
|
||||
|
||||
public function handle(Request $request, $type = HttpKernelInterface::MASTER_REQUEST, $catch = false)
|
||||
{
|
||||
$this->backendRequest = $request;
|
||||
|
||||
return parent::handle($request, $type, $catch);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user