You are here

private function HttpCache::restoreResponseBody in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 vendor/symfony/http-kernel/HttpCache/HttpCache.php \Symfony\Component\HttpKernel\HttpCache\HttpCache::restoreResponseBody()

Restores the Response body.

Parameters

Request $request A Request instance:

Response $response A Response instance:

1 call to HttpCache::restoreResponseBody()
HttpCache::handle in vendor/symfony/http-kernel/HttpCache/HttpCache.php
Handles a Request to convert it to a Response.

File

vendor/symfony/http-kernel/HttpCache/HttpCache.php, line 627

Class

HttpCache
Cache provides HTTP caching.

Namespace

Symfony\Component\HttpKernel\HttpCache

Code

private function restoreResponseBody(Request $request, Response $response) {
  if ($request
    ->isMethod('HEAD') || 304 === $response
    ->getStatusCode()) {
    $response
      ->setContent(null);
    $response->headers
      ->remove('X-Body-Eval');
    $response->headers
      ->remove('X-Body-File');
    return;
  }
  if ($response->headers
    ->has('X-Body-Eval')) {
    ob_start();
    if ($response->headers
      ->has('X-Body-File')) {
      include $response->headers
        ->get('X-Body-File');
    }
    else {
      eval('; ?>' . $response
        ->getContent() . '<?php ;');
    }
    $response
      ->setContent(ob_get_clean());
    $response->headers
      ->remove('X-Body-Eval');
    if (!$response->headers
      ->has('Transfer-Encoding')) {
      $response->headers
        ->set('Content-Length', strlen($response
        ->getContent()));
    }
  }
  elseif ($response->headers
    ->has('X-Body-File')) {
    $response
      ->setContent(file_get_contents($response->headers
      ->get('X-Body-File')));
  }
  else {
    return;
  }
  $response->headers
    ->remove('X-Body-File');
}