Permalink
Browse files

Merge pull request #44 from rkneufeld/app-tools-no-cache

App-tools now serves every request with Cache-Control: no-cache
  • Loading branch information...
2 parents 6105cb1 + db038b5 commit b5353b3988392967a8907d2c7a1b3b2b07d7720a @timewald timewald committed Apr 3, 2013
View
8 app-tools/src/io/pedestal/app_tools/service.clj
@@ -14,7 +14,7 @@
[io.pedestal.service.log :as log]
;; the impl dependencies will go away
;; these next two will collapse to one
- [io.pedestal.service.interceptor :as interceptor :refer [definterceptorfn]]
+ [io.pedestal.service.interceptor :as interceptor :refer [definterceptorfn defon-response]]
[io.pedestal.service.http :as bootstrap]
[io.pedestal.service.http.impl.servlet-interceptor :as servlet-interceptor]
[io.pedestal.service.http.route.definition :refer [expand-routes]]
@@ -39,6 +39,9 @@
(assoc context :response (ring-response/redirect (str "http://" host ":" port uri)))
context)))))
+(defon-response default-cache-control-to-no-cache
+ [response]
+ (update-in response [:headers "Cache-Control"] #(or % "no-cache")))
;; define service routes
(defn dev-routes
@@ -56,7 +59,8 @@
;; sure you include routing and set it up right for
;; dev-mode. If you do, many other keys for configuring
;; default interceptors will be ignored.
- ::bootstrap/interceptors [bootstrap/not-found
+ ::bootstrap/interceptors [default-cache-control-to-no-cache
+ bootstrap/not-found
bootstrap/log-request
servlet-interceptor/exception-debug
middlewares/cookies
View
25 app-tools/test/io/pedestal/app_tools/test/service.clj
@@ -0,0 +1,25 @@
+; Copyright 2013 Relevance, Inc.
+
+; The use and distribution terms for this software are covered by the
+; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0)
+; which can be found in the file epl-v10.html at the root of this distribution.
+;
+; By using this software in any fashion, you are agreeing to be bound by
+; the terms of this license.
+;
+; You must not remove this notice, or any other, from this software.
+
+(ns io.pedestal.app-tools.test.service
+ (:use io.pedestal.app-tools.service
+ clojure.test))
+
+(deftest test-default-cache-control-to-no-cache-interceptor
+ (let [leave (:leave default-cache-control-to-no-cache)
+ empty-response {}
+ response-with-cache-control {:response {:headers {"Cache-Control" "max-age=42"}}}]
+ (is (= (leave {})
+ {:response {:headers {"Cache-Control" "no-cache"}}})
+ "Response Cache-Control defaults to no-cache")
+ (is (= (leave response-with-cache-control)
+ response-with-cache-control)
+ "Response Cache-Control isn't modified if already specified")))

0 comments on commit b5353b3

Please sign in to comment.