From 97c2c84c456b5aaebec00b1da94c88b982a59bbf Mon Sep 17 00:00:00 2001 From: Peter Taoussanis Date: Sat, 8 Mar 2014 16:51:19 +0700 Subject: [PATCH] Move `session-swap` to Encore util --- project.clj | 2 +- src/taoensso/touchstone/ring.clj | 16 ++-------------- 2 files changed, 3 insertions(+), 15 deletions(-) diff --git a/project.clj b/project.clj index c1e013d..cabc5d0 100644 --- a/project.clj +++ b/project.clj @@ -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"]] diff --git a/src/taoensso/touchstone/ring.clj b/src/taoensso/touchstone/ring.clj index 372dab7..be8bc55 100644 --- a/src/taoensso/touchstone/ring.clj +++ b/src/taoensso/touchstone/ring.clj @@ -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." @@ -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 @@ -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))))))