 (defn- set-session-cookie
   "Set the session cookie on the response if required."
   [request response session]
-  (let [new?    (:new-session? request)
-        cookie  (session-cookie new? session)
-        update  (set-cookie :compojure-session cookie, :path "/")]
+  (let [new?   (:new-session? request)
+        cookie (session-cookie new? session)
+        update (set-cookie :compojure-session cookie, :path "/")]
     (if cookie
       (update-response request response update)
       response)))

(defn- save-handler-session
  "Save the session for a handler if required."
  [request response session]
  (cond (and (contains? response :session)
             (nil? (response :session)))
        (destroy-session session)
        (or (:session response)
            (contains? *session-repo* :expires)
            (:new-session? request)
            (not-empty (:flash request)))
        (write-session session)))

(defn with-session
  "Wrap a handler in a session of the specified type. Session type defaults to
  :memory if not supplied."
  ([handler]
    (with-session handler {:type :memory}))
  ([handler session-repo]
    (fn [request]
      (binding [*session-repo* session-repo]

      (do
        (destroy-session session)
        (new-request-session request))
      (assoc request :session (assoc-expiry session)))
    (new-request-session request)))

(defn- assoc-request-flash
