       (binding [*current-user-id* current-user-id
                 *current-user* (if-not current-user-id (atom nil)
                                                        (delay (sel-current-user current-user-id)))]
-        (handler request)))))+        (handler request)))))



(def SESSION_COOKIE "metabase.SESSION_ID")
(def SESSION_HEADER "X-METABASE-SESSION")


(defn wrap-sessionid

   http headers for `X-METABASE-SESSION`.  If neither is found then then no keyword is bound to the request."
  [handler]
  (fn [{:keys [cookies headers] :as request}]
    (if-let [session-id (or (get-in cookies [SESSION_COOKIE :value]) (headers SESSION_HEADER))]
      ;; alternatively we could always associate the keyword and just let it be nil if there is no value
      (handler (assoc request :metabase-sessionid session-id))
      (handler request))))
