From e024fa62cd11985bcff34eebacdbcc0d89b4311d Mon Sep 17 00:00:00 2001 From: Magnar Sveen Date: Sun, 29 Dec 2013 00:09:47 +0100 Subject: [PATCH] Including both Cache-Control and Expires headers apparently isn't redundant. This reverts commit 6055f0d620f67d637682ce744cd666a1d402fc82. --- .../optimizations/add_cache_busted_expires_headers.clj | 1 + .../optimizations/add_cache_busted_expires_headers_test.clj | 4 +++- test/optimus/optimizations_test.clj | 3 ++- test/optimus/strategies_test.clj | 4 ++-- 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/optimus/optimizations/add_cache_busted_expires_headers.clj b/src/optimus/optimizations/add_cache_busted_expires_headers.clj index 3f724b7..d58e7f1 100644 --- a/src/optimus/optimizations/add_cache_busted_expires_headers.clj +++ b/src/optimus/optimizations/add_cache_busted_expires_headers.clj @@ -22,6 +22,7 @@ (subs (digest/sha-1 (get-contents file)) 0 12) (:path file))) (assoc :original-path (original-path file)) + (assoc-in [:headers "Cache-Control"] "max-age=315360000") (assoc-in [:headers "Expires"] (http-date-formatter (time/plus (time/now) (time/days 3650)))))) diff --git a/test/optimus/optimizations/add_cache_busted_expires_headers_test.clj b/test/optimus/optimizations/add_cache_busted_expires_headers_test.clj index 707dcb9..b60436e 100644 --- a/test/optimus/optimizations/add_cache_busted_expires_headers_test.clj +++ b/test/optimus/optimizations/add_cache_busted_expires_headers_test.clj @@ -22,7 +22,8 @@ {:path "/f549e6e556ea/code.js" :original-path "/code.js" :contents "1 + 2" - :headers {"Expires" "Fri, 28 Jul 2023 00:00:00 GMT"}}]) + :headers {"Cache-Control" "max-age=315360000" + "Expires" "Fri, 28 Jul 2023 00:00:00 GMT"}}]) (fact "While it's important that the :original-path property is set, so @@ -45,6 +46,7 @@ (map (juxt :path :headers))) => [["/c.js" {"Last-Modified" "Fri, 28 Jul 2023 00:00:00 GMT"}] ["/f549e6e556ea/c.js" {"Last-Modified" "Fri, 28 Jul 2023 00:00:00 GMT" + "Cache-Control" "max-age=315360000" "Expires" "Fri, 28 Jul 2023 00:00:00 GMT"}]]) (fact diff --git a/test/optimus/optimizations_test.clj b/test/optimus/optimizations_test.clj index 8497eca..fc49c64 100644 --- a/test/optimus/optimizations_test.clj +++ b/test/optimus/optimizations_test.clj @@ -6,7 +6,8 @@ (:use midje.sweet)) (with-redefs [time/now (fn [] (time/date-time 2013 07 30))] - (def headers {"Expires" "Fri, 28 Jul 2023 00:00:00 GMT"}) + (def headers {"Cache-Control" "max-age=315360000" + "Expires" "Fri, 28 Jul 2023 00:00:00 GMT"}) (fact "This is a big integration test, for sure. It bundles bundles, it diff --git a/test/optimus/strategies_test.clj b/test/optimus/strategies_test.clj index 72167fe..45fb9a9 100644 --- a/test/optimus/strategies_test.clj +++ b/test/optimus/strategies_test.clj @@ -22,10 +22,10 @@ "Headers are included." (defn get-assets [] - [{:path "/more.js" :contents "3 + 4" :headers {"Expires" "Fri, 28 Jul 2023 00:00:00 GMT"}}]) + [{:path "/more.js" :contents "3 + 4" :headers {"Cache-Control" "max-age=315360000"}}]) (let [app (serve-live-assets noop get-assets dont-optimize {})] - (app {:uri "/more.js"}) => {:status 200 :body "3 + 4" :headers {"Expires" "Fri, 28 Jul 2023 00:00:00 GMT"}})) + (app {:uri "/more.js"}) => {:status 200 :body "3 + 4" :headers {"Cache-Control" "max-age=315360000"}})) (fact "Assets are fetched for each request. We wouldn't want to restart the