Exemplo n.º 1
0
 public function createResponse(IAsset $asset, Request $request)
 {
     $response = new DispatchResponse();
     //Set the correct content type based on the asset
     $response->headers->set('Content-Type', $asset->getContentType());
     $response->headers->set('X-Content-Type-Options', 'nosniff');
     //Ensure the cache varies on the encoding
     //Domain specific content will vary on the uri itself
     $response->headers->set("Vary", "Accept-Encoding");
     $content = $asset->getContent();
     //Set the etag to the hash of the request uri, as it is in itself a hash
     $response->setEtag(md5($content));
     $response->setPublic();
     //This resource should last for 30 days in cache
     $response->setMaxAge(2592000);
     $response->setSharedMaxAge(2592000);
     $response->setExpires((new \DateTime())->add(new \DateInterval('P30D')));
     //Set the last modified date to now
     $date = new \DateTime();
     $date->setTimezone(new \DateTimeZone('UTC'));
     $response->headers->set('Last-Modified', $date->format('D, d M Y H:i:s') . ' GMT');
     //Check to see if the client already has the content
     if ($request->server->has('HTTP_IF_MODIFIED_SINCE')) {
         $response->setNotModified();
     } else {
         $response->setContent($content);
     }
     return $response;
 }