mirror of
https://github.com/metosin/reitit.git
synced 2026-01-08 08:19:51 +00:00
Add spec
This commit is contained in:
parent
888856b5cc
commit
78a1cc144e
1 changed files with 14 additions and 4 deletions
|
|
@ -1,10 +1,13 @@
|
|||
(ns reitit.ring.middleware.session
|
||||
(:require
|
||||
[clojure.spec.alpha :as s]
|
||||
[ring.middleware.session :as session]
|
||||
[ring.middleware.session.memory :as memory]))
|
||||
|
||||
(s/def ::spec (s/keys :opt-un [::session]))
|
||||
|
||||
(def ^:private store
|
||||
"The in-memory session store.
|
||||
"The default shared in-memory session store.
|
||||
|
||||
This is used when no `:session` key is provided to the middleware."
|
||||
(atom {}))
|
||||
|
|
@ -12,12 +15,19 @@
|
|||
(def session-middleware
|
||||
"Middleware for session.
|
||||
|
||||
Decodes the session from a request map into the `:session` value and updates the session store
|
||||
based on the response's `:session` value.
|
||||
Enter:
|
||||
Add the `:session` key into the request map based on the `:cookies`
|
||||
in the request map.
|
||||
|
||||
Exit:
|
||||
When `:session` key presents in the response map, update the session
|
||||
store with its value. Then remove `:session` from the response map.
|
||||
|
||||
| key | description |
|
||||
| -------------|-------------|
|
||||
| `:session` | `ring.middleware.session.store/SessionStore` instance. Use `ring.middleware.session.memory/MemoryStore` by default."
|
||||
{:name :session
|
||||
:compile (fn [{:keys [session] :or {session {:store (memory/memory-store store)}}} _]
|
||||
:spec ::spec
|
||||
:compile (fn [{:keys [session]
|
||||
:or {session {:store (memory/memory-store store)}}} _]
|
||||
{:wrap #(session/wrap-session % session)})})
|
||||
|
|
|
|||
Loading…
Reference in a new issue