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

src/session.qz:154

Class methods

def self.new(*, store: Bezel::Session::Store) -> Bezel::Plug::Session

A plug of a store.

src/session.qz:160

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).

src/session.qz:165

Methods

def call(conn: Bezel::Conn) -> Bezel::Conn

The connection changed by this plug.

from Bezel::Plug

src/session.qz:170

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

src/session.qz:172