protected function HttpCache::forward in Zircon Profile 8
Same name and namespace in other branches
- 8.0 vendor/symfony/http-kernel/HttpCache/HttpCache.php \Symfony\Component\HttpKernel\HttpCache\HttpCache::forward()
Forwards the Request to the backend and returns the Response.
Parameters
Request $request A Request instance:
bool $catch Whether to catch exceptions or not:
Response $entry A Response instance (the stale entry if present, null otherwise):
Return value
3 calls to HttpCache::forward()
- HttpCache::fetch in vendor/
symfony/ http-kernel/ HttpCache/ HttpCache.php - Forwards the Request to the backend and determines whether the response should be stored.
- HttpCache::pass in vendor/
symfony/ http-kernel/ HttpCache/ HttpCache.php - Forwards the Request to the backend without storing the Response in the cache.
- HttpCache::validate in vendor/
symfony/ http-kernel/ HttpCache/ HttpCache.php - Validates that a cache entry is fresh.
File
- vendor/
symfony/ http-kernel/ HttpCache/ HttpCache.php, line 462
Class
- HttpCache
- Cache provides HTTP caching.
Namespace
Symfony\Component\HttpKernel\HttpCacheCode
protected function forward(Request $request, $catch = false, Response $entry = null) {
if ($this->surrogate) {
$this->surrogate
->addSurrogateCapability($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');
// make sure HttpCache is a trusted proxy
if (!in_array('127.0.0.1', $trustedProxies = Request::getTrustedProxies())) {
$trustedProxies[] = '127.0.0.1';
Request::setTrustedProxies($trustedProxies);
}
// 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
// we don't implement the stale-if-error on Requests, which is nonetheless part of the RFC
if (null !== $entry && in_array($response
->getStatusCode(), array(
500,
502,
503,
504,
))) {
if (null === ($age = $entry->headers
->getCacheControlDirective('stale-if-error'))) {
$age = $this->options['stale_if_error'];
}
if (abs($entry
->getTtl()) < $age) {
$this
->record($request, 'stale-if-error');
return $entry;
}
}
$this
->processResponseBody($request, $response);
if ($this
->isPrivateRequest($request) && !$response->headers
->hasCacheControlDirective('public')) {
$response
->setPrivate(true);
}
elseif ($this->options['default_ttl'] > 0 && null === $response
->getTtl() && !$response->headers
->getCacheControlDirective('must-revalidate')) {
$response
->setTtl($this->options['default_ttl']);
}
return $response;
}