public function HttpCache::handle

@api

Overrides HttpKernelInterface::handle

File

drupal/core/vendor/symfony/http-kernel/Symfony/Component/HttpKernel/HttpCache/HttpCache.php, line 172

Class

HttpCache
Cache provides HTTP caching.

Namespace

Symfony\Component\HttpKernel\HttpCache

Code

public function handle(Request $request, $type = HttpKernelInterface::MASTER_REQUEST, $catch = true) {

  // FIXME: catch exceptions and implement a 500 error page here? -> in Varnish, there is a built-in error page mechanism
  if (HttpKernelInterface::MASTER_REQUEST === $type) {
    $this->traces = array();
    $this->request = $request;
    if (null !== $this->esi) {
      $this->esiCacheStrategy = $this->esi
        ->createCacheStrategy();
    }
  }
  $path = $request
    ->getPathInfo();
  if ($qs = $request
    ->getQueryString()) {
    $path .= '?' . $qs;
  }
  $this->traces[$request
    ->getMethod() . ' ' . $path] = array();
  if (!$request
    ->isMethodSafe()) {
    $response = $this
      ->invalidate($request, $catch);
  }
  elseif ($request->headers
    ->has('expect')) {
    $response = $this
      ->pass($request, $catch);
  }
  else {
    $response = $this
      ->lookup($request, $catch);
  }
  $this
    ->restoreResponseBody($request, $response);
  $response
    ->setDate(new \DateTime(null, new \DateTimeZone('UTC')));
  if (HttpKernelInterface::MASTER_REQUEST === $type && $this->options['debug']) {
    $response->headers
      ->set('X-Symfony-Cache', $this
      ->getLog());
  }
  if (null !== $this->esi) {
    if (HttpKernelInterface::MASTER_REQUEST === $type) {
      $this->esiCacheStrategy
        ->update($response);
    }
    else {
      $this->esiCacheStrategy
        ->add($response);
    }
  }
  $response
    ->prepare($request);
  $response
    ->isNotModified($request);
  return $response;
}