Exemplo n.º 1
0
 public function handle(Event $event, Response $response)
 {
     if (HttpKernelInterface::MASTER_REQUEST !== $event->getParameter('request_type')) {
         return $response;
     }
     $request = $event->getParameter('request');
     if ('3' === substr($response->getStatusCode(), 0, 1) || $response->headers->has('Content-Type') && false === strpos($response->headers->get('Content-Type'), 'html') || 'html' !== $request->getRequestFormat() || $request->isXmlHttpRequest()) {
         return $response;
     }
     $response->setContent($this->injectToolbar($request, $response));
     return $response;
 }
Exemplo n.º 2
0
 /**
  * Replaces a Response ESI tags with the included resource content.
  *
  * @param Symfony\Components\HttpFoundation\Request  $request  A Request instance
  * @param Symfony\Components\HttpFoundation\Response $response A Response instance
  */
 public function process(Request $request, Response $response)
 {
     $this->request = $request;
     $type = $response->headers->get('Content-Type');
     if (empty($type)) {
         $type = 'text/html';
     }
     if (!in_array($type, $this->contentTypes)) {
         return $response;
     }
     // we don't use a proper XML parser here as we can have ESI tags in a plain text response
     $content = $response->getContent();
     $content = preg_replace_callback('#<esi\\:include\\s+(.+?)\\s*/>#', array($this, 'handleEsiIncludeTag'), $content);
     $content = preg_replace('#<esi\\:comment[^>]*/>#', '', $content);
     $content = preg_replace('#<esi\\:remove>.*?</esi\\:remove>#', '', $content);
     $response->setContent($content);
     $response->headers->set('X-Body-Eval', 'ESI');
     // remove ESI/1.0 from the Surrogate-Control header
     $value = $response->headers->get('Surrogate-Control');
     if (preg_match('#^content="ESI/1.0"$#', $value)) {
         $response->headers->delete('Surrogate-Control');
     } else {
         $response->headers->set('Surrogate-Control', preg_replace('#ESI/1.0#', '', $value));
     }
 }
Exemplo n.º 3
0
 /**
  * Restores the Response body.
  *
  * @param Symfony\Components\HttpFoundation\Response $response A Response instance
  *
  * @return Symfony\Components\HttpFoundation\Response A Response instance
  */
 protected function restoreResponseBody(Response $response)
 {
     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->delete('X-Body-Eval');
     } elseif ($response->headers->has('X-Body-File')) {
         $response->setContent(file_get_contents($response->headers->get('X-Body-File')));
     } else {
         return;
     }
     $response->headers->delete('X-Body-File');
     if (!$response->headers->has('Transfer-Encoding')) {
         $response->headers->set('Content-Length', strlen($response->getContent()));
     }
 }