Przeglądaj źródła

Adding caching headers

Added etags and last modified headers for better caching.
Rafael Dohms 12 lat temu
rodzic
commit
76fe563284

+ 7 - 1
src/Packagist/WebBundle/Controller/FeedController.php

@@ -171,7 +171,13 @@ class FeedController extends Controller
      */
     protected function buildResponse($feed, $format)
     {
-        $response = new Response($feed->export($format), 200, array('Content-Type' => "application/$format+xml"));
+        $content = $feed->export($format);
+        $lastContent = $feed->getEntry(0);
+        $etag = md5($content);
+
+        $response = new Response($content, 200, array('Content-Type' => "application/$format+xml"));
+        $response->setEtag($etag);
+        $response->setLastModified($lastContent->getDateModified());
 
         return $response;
     }