Skip to content

Commit

Permalink
Merge pull request #44 from rkneufeld/app-tools-no-cache
Browse files Browse the repository at this point in the history
App-tools now serves every request with Cache-Control: no-cache
  • Loading branch information
timewald committed Apr 3, 2013
2 parents 6105cb1 + db038b5 commit b5353b3
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
8 changes: 6 additions & 2 deletions app-tools/src/io/pedestal/app_tools/service.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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]]
Expand All @@ -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
Expand All @@ -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
Expand Down
25 changes: 25 additions & 0 deletions app-tools/test/io/pedestal/app_tools/test/service.clj
Original file line number Diff line number Diff line change
@@ -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.