View Source Plug.Session.Store behaviour (Plug v1.14.2)
Specification for session stores.
Link to this section Summary
Types
The cookie value that will be sent in cookie headers. This value should be base64 encoded to avoid security issues.
The session contents, the final data to be stored after it has been built
with Plug.Conn.put_session/3
and the other session manipulating functions.
The internal reference to the session in the store.
Callbacks
Removes the session associated with given session id from the store.
Parses the given cookie.
Initializes the store.
Stores the session associated with given session id.
Functions
Gets the store name from an atom or a module.
Link to this section Types
@type cookie() :: binary()
The cookie value that will be sent in cookie headers. This value should be base64 encoded to avoid security issues.
@type session() :: map()
The session contents, the final data to be stored after it has been built
with Plug.Conn.put_session/3
and the other session manipulating functions.
@type sid() :: term() | nil
The internal reference to the session in the store.
Link to this section Callbacks
@callback delete(conn :: Plug.Conn.t(), sid(), opts :: Plug.opts()) :: :ok
Removes the session associated with given session id from the store.
@callback get(conn :: Plug.Conn.t(), cookie(), opts :: Plug.opts()) :: {sid(), session()}
Parses the given cookie.
Returns a session id and the session contents. The session id is any value that can be used to identify the session by the store.
The session id may be nil in case the cookie does not identify any value in the store. The session contents must be a map.
Initializes the store.
The options returned from this function will be given
to get/3
, put/4
and delete/3
.
@callback put(conn :: Plug.Conn.t(), sid(), any(), opts :: Plug.opts()) :: cookie()
Stores the session associated with given session id.
If nil
is given as id, a new session id should be
generated and returned.
Link to this section Functions
Gets the store name from an atom or a module.
iex> Plug.Session.Store.get(CustomStore)
CustomStore
iex> Plug.Session.Store.get(:cookie)
Plug.Session.COOKIE