Skip to content

Commit

Permalink
Move session-swap to Encore util
Browse files Browse the repository at this point in the history
  • Loading branch information
ptaoussanis committed Mar 8, 2014
1 parent 1ea8754 commit 97c2c84
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 15 deletions.
2 changes: 1 addition & 1 deletion project.clj
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
*assert* true}
:dependencies
[[org.clojure/clojure "1.4.0"]
[com.taoensso/encore "0.9.2"]
[com.taoensso/encore "0.9.7"]
[com.taoensso/carmine "2.4.6"]
[org.clojure/math.combinatorics "0.0.7"]]

Expand Down
16 changes: 2 additions & 14 deletions src/taoensso/touchstone/ring.clj
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"Touchstone middleware for Ring."
{:author "Peter Taoussanis"}
(:require [clojure.string :as str]
[taoensso.encore :as encore]
[taoensso.touchstone :as touchstone]))

(defn bot-user-agent? "Simple test for honest bots."
Expand All @@ -14,19 +15,6 @@

(comment (bot-user-agent? {"user-agent" "GoogleBot"}))

(defn session-swap
"Small util to help correctly manage (modify) funtional sessions."
[req resp f & args]
(when resp
(if (contains? resp :session) ; Use response session (may be nil)
(assoc resp :session (apply f (:session resp) args))
(assoc resp :session (apply f (:session req) args)))))

(comment
(session-swap {:session {:req? true}} {:session nil} assoc :new-k :new-v)
(session-swap {:session {:req? true}} {:session {:resp? true}} assoc :new-k :new-v)
(session-swap {:session {:old? true}} {} assoc :new-k :new-v))

(defn wrap-test-subject-id
"Ring middleware that generates, sessionizes, and binds a test-subject id for
requests eligible for split-testing (by default this excludes clients that
Expand All @@ -44,4 +32,4 @@
(let [new-id (rand-int 2147483647)
response (touchstone/with-test-subject new-id
(handler (assoc request :ts-id new-id)))]
(session-swap request response assoc :ts-id new-id))))))
(encore/session-swap request response assoc :ts-id new-id))))))

0 comments on commit 97c2c84

Please sign in to comment.