class Bezel::Plug::Accepts
include Bezel::Plug
Chooses the response's format among formats (["html", "json"]) and
sets Conn#format (:html): the _format parameter when there is
one, else the request's Accept (its media ranges by their quality;
*/* or no Accept takes the first of formats). A request that
accepts none of them, or names another _format, is
Bezel::NotAcceptable (406).
The formats and their media types: html (text/html, and
application/xhtml+xml when named exactly, so that application/* is
no HTML), json
(application/json), text (text/plain), xml (application/xml
and text/xml), csv (text/csv).
req = HTTP::Server::Request.get("/", HTTP::Headers.of({"Accept" => "application/json, text/html;q=0.5"}))
Bezel::Plug::Accepts.new(["html", "json"]).call(Bezel::Conn.build(req)).format # => :json
Constants
TYPES: Hash[String, Array[String]]
The media types of the formats known.
EXACT: Hash[String, Array[String]]
Media types a format takes only when the header names them exactly.
Class methods
def self.new(formats: Array[String]) -> Bezel::Plug::Accepts
The plug, accepting formats (preferred first).
Methods
def call(conn: Bezel::Conn) -> Bezel::Conn
The connection changed by this plug.
from Bezel::Plug