Merge branch '2.1' into 2.2
* 2.1: [FrameworkBundle] tweaked reference dumper command (see #7093) [HttpKernel] added some tests for previous merge Fix REMOTE_ADDR for cached subrequests [Process] Warn user with a useful message when tmpfile() failed Conflicts: src/Symfony/Bundle/FrameworkBundle/Command/ConfigDumpReferenceCommand.php
This commit is contained in:
commit
0de369ae38
@ -418,18 +418,6 @@ class HttpCache implements HttpKernelInterface, TerminableInterface
|
||||
$subRequest->headers->remove('if_modified_since');
|
||||
$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
|
||||
// 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')) {
|
||||
@ -460,6 +448,18 @@ class HttpCache implements HttpKernelInterface, TerminableInterface
|
||||
$this->esi->addSurrogateEsiCapability($request);
|
||||
}
|
||||
|
||||
// modify the X-Forwarded-For header if needed
|
||||
$forwardedFor = $request->headers->get('X-Forwarded-For');
|
||||
if ($forwardedFor) {
|
||||
$request->headers->set('X-Forwarded-For', $forwardedFor.', '.$request->server->get('REMOTE_ADDR'));
|
||||
} else {
|
||||
$request->headers->set('X-Forwarded-For', $request->server->get('REMOTE_ADDR'));
|
||||
}
|
||||
|
||||
// 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.
|
||||
$request->server->set('REMOTE_ADDR', '127.0.0.1');
|
||||
|
||||
// always a "master" request (as the real master request can be in cache)
|
||||
$response = $this->kernel->handle($request, HttpKernelInterface::MASTER_REQUEST, $catch);
|
||||
// FIXME: we probably need to also catch exceptions if raw === true
|
||||
|
@ -1066,4 +1066,13 @@ class HttpCacheTest extends HttpCacheTestCase
|
||||
array('10.0.0.2, 10.0.0.3', '10.0.0.2, 10.0.0.3, 10.0.0.1'),
|
||||
);
|
||||
}
|
||||
|
||||
public function testXForwarderForHeaderForPassRequests()
|
||||
{
|
||||
$this->setNextResponse();
|
||||
$server = array('REMOTE_ADDR' => '10.0.0.1');
|
||||
$this->request('POST', '/', $server);
|
||||
|
||||
$this->assertEquals('10.0.0.1', $this->kernel->getBackendRequest()->headers->get('X-Forwarded-For'));
|
||||
}
|
||||
}
|
||||
|
@ -232,6 +232,9 @@ class Process
|
||||
$this->fileHandles = array(
|
||||
self::STDOUT => tmpfile(),
|
||||
);
|
||||
if (false === $this->fileHandles[self::STDOUT]) {
|
||||
throw new RuntimeException('A temporary file could not be opened to write the process output to, verify that your TEMP environment variable is writable');
|
||||
}
|
||||
$this->readBytes = array(
|
||||
self::STDOUT => 0,
|
||||
);
|
||||
|
Reference in New Issue
Block a user