Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

app-tools cache control interceptor leaves existing alone

  • Loading branch information...
commit db038b55590ff96e70a221923c9787c8d18bac8f 1 parent e856f8f
@rkneufeld rkneufeld authored
View
12 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 definterceptor]]
+ [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,11 +39,9 @@
(assoc context :response (ring-response/redirect (str "http://" host ":" port uri)))
context)))))
-(definterceptor set-cache-control-no-cache
- (interceptor/on-response
- ::set-cache-control-no-cache
- (fn [response]
- (assoc-in response [:headers "Cache-Control"] "no-cache"))))
+(defon-response default-cache-control-to-no-cache
+ [response]
+ (update-in response [:headers "Cache-Control"] #(or % "no-cache")))
;; define service routes
(defn dev-routes
@@ -61,7 +59,7 @@
;; 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 [set-cache-control-no-cache
+ ::bootstrap/interceptors [default-cache-control-to-no-cache
bootstrap/not-found
bootstrap/log-request
servlet-interceptor/exception-debug
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")))
Please sign in to comment.
Something went wrong with that request. Please try again.