Beispiel #1
0
 /**
  * Handles a Request.
  *
  * @param Symfony\Components\HttpKernel\Request $request A Request instance
  * @param integer                               $type    The type of the request (one of HttpKernelInterface::MASTER_REQUEST, HttpKernelInterface::FORWARDED_REQUEST, or HttpKernelInterface::EMBEDDED_REQUEST)
  * @param Boolean                               $raw     Whether to catch exceptions or not (this is NOT used in this context)
  *
  * @return Symfony\Components\HttpKernel\Response A Response instance
  */
 public function handle(Request $request = null, $type = HttpKernelInterface::MASTER_REQUEST, $raw = false)
 {
     // FIXME: catch exceptions and implement a 500 error page here? -> in Varnish, there is a built-it error page mechanism
     if (null === $request) {
         $request = new Request();
     }
     if (HttpKernelInterface::MASTER_REQUEST === $type) {
         $this->traces = array();
         $this->request = $request;
     }
     $this->traces[$request->getMethod() . ' ' . $request->getPathInfo()] = array();
     if (!$request->isMethodSafe($request)) {
         $response = $this->invalidate($request);
     } elseif ($request->headers->has('expect')) {
         $response = $this->pass($request);
     } else {
         $response = $this->lookup($request);
     }
     $response->isNotModified($request);
     if ('head' === strtolower($request->getMethod())) {
         $response->setContent('');
     } else {
         $this->restoreResponseBody($response);
     }
     if (HttpKernelInterface::MASTER_REQUEST === $type && $this->options['debug']) {
         $response->headers->set('X-Symfony-Cache', $this->getLog());
     }
     return $response;
 }