class Bezel::Plug::Session
include Bezel::Plug
Loads the request's session from store (conn.session) and, once the
rest of the pipeline has answered, saves it when it changed (a cookie
store sets its cookie). Not saved when a plug raised: the error page
leaves the session as it was (so a first visit's CSRF secret is made
again on the next request).
s = Bezel::Plug::Session.new(key: "_shop")
plugs: Array[Bezel::Plug] = [s, Bezel.plug { |c| c.put_session("user_id", "7").text("hi") }]
out = Bezel::Plug.run(plugs, Bezel::Conn.build(HTTP::Server::Request.get("/")))
(out.resp_headers["set-cookie"] || "").start_with?("_shop=") # => true
Class methods
def self.new(*, store: Bezel::Session::Store) -> Bezel::Plug::Session
A plug of a store.
def self.new(*, key: String, max_age: Int? = …, secure: Bool? = …, same_site: String = …, domain: String? = …) -> Bezel::Plug::Session
A plug of a cookie store (the cookie store's options).
Methods
def call(conn: Bezel::Conn) -> Bezel::Conn
The connection changed by this plug.
from Bezel::Plug
def wrap(conn: Bezel::Conn, rest: (Bezel::Conn) -> Bezel::Conn) -> Bezel::Conn
Runs this plug, then rest (the plugs after it) unless it halted.
Override it to act around the rest: its result is the request's.
from Bezel::Plug