diff --git a/src/Symfony/Component/HttpKernel/HttpCache/HttpCache.php b/src/Symfony/Component/HttpKernel/HttpCache/HttpCache.php index 97e365008b..ae918e1543 100644 --- a/src/Symfony/Component/HttpKernel/HttpCache/HttpCache.php +++ b/src/Symfony/Component/HttpKernel/HttpCache/HttpCache.php @@ -413,18 +413,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')) { @@ -455,6 +443,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