mirror of
https://github.com/metosin/reitit.git
synced 2026-02-14 23:35:16 +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
|
(ns reitit.ring.middleware.session
|
||||||
(:require
|
(:require
|
||||||
|
[clojure.spec.alpha :as s]
|
||||||
[ring.middleware.session :as session]
|
[ring.middleware.session :as session]
|
||||||
[ring.middleware.session.memory :as memory]))
|
[ring.middleware.session.memory :as memory]))
|
||||||
|
|
||||||
|
(s/def ::spec (s/keys :opt-un [::session]))
|
||||||
|
|
||||||
(def ^:private store
|
(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."
|
This is used when no `:session` key is provided to the middleware."
|
||||||
(atom {}))
|
(atom {}))
|
||||||
|
|
@ -12,12 +15,19 @@
|
||||||
(def session-middleware
|
(def session-middleware
|
||||||
"Middleware for session.
|
"Middleware for session.
|
||||||
|
|
||||||
Decodes the session from a request map into the `:session` value and updates the session store
|
Enter:
|
||||||
based on the response's `:session` value.
|
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 |
|
| key | description |
|
||||||
| -------------|-------------|
|
| -------------|-------------|
|
||||||
| `:session` | `ring.middleware.session.store/SessionStore` instance. Use `ring.middleware.session.memory/MemoryStore` by default."
|
| `:session` | `ring.middleware.session.store/SessionStore` instance. Use `ring.middleware.session.memory/MemoryStore` by default."
|
||||||
{:name :session
|
{: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)})})
|
{:wrap #(session/wrap-session % session)})})
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue