March Docs

Conn

Bastion.Conn — higher-level helpers for the HttpServer.Conn type.

The underlying connection type is HttpServer.Conn. This module adds ergonomic shortcuts and parsed views on top of the raw accessors that HttpServer already provides.

All functions in this module accept and return HttpServer.Conn values. There is no separate Bastion.Conn type — this avoids duplicating the transport-layer type and keeps conversion overhead at zero.

Functions

fnacceptaccept(conn : Conn) : Option(String)#

Returns the value of the Accept request header, if present.

fnafter_send_hooksafter_send_hooks(conn : Conn) : List(String)#

Return the list of registered after-send hook keys.

Called by BastionServer after send_resp to dispatch the hooks.
fnassignassign(conn : Conn, key : String, value : String) : Conn#

Store a key/value pair in the conn's assigns map. Returns updated conn.

fncontent_typecontent_type(conn : Conn) : Option(String)#

Returns the value of the Content-Type request header, if present. Equivalent to get_req_header(conn, \"content-type\").

fnget_assignget_assign(conn : Conn, key : String) : Option(String)#

Look up a value stored in conn's assigns map by key. Assigns are set by middleware or router param extraction. Returns None if the key is not present.

fnget_form_paramget_form_param(conn : Conn, key : String) : Option(String)#

Look up a single URL-encoded form body parameter by name.

Parses the request body as application/x-www-form-urlencoded.
Returns None if the param is not present.

    Conn.get_form_param(conn, "email")  -- Some("[email protected]") or None
fnget_req_headerget_req_header(conn : Conn, name : String) : Option(String)#

Look up a request header by name (case-insensitive). Returns None if missing.

fnhalthalt(conn : Conn) : Conn#

Halt the conn without setting a response (used by auth middleware to short-circuit).

fnhaltedhalted(conn : Conn) : Bool#

Returns true if the response has been sent (conn is halted).

fnmethodmethod(conn : Conn) : Atom#

Returns the HTTP method of the request (Get, Post, Put, …).

fnpathpath(conn : Conn) : String#

Returns the raw request path string, e.g. \

fnpath_infopath_info(conn : Conn) : List(String)#

Returns the path split on '/', empty segments filtered out.

fnput_resp_headerput_resp_header(conn : Conn, name : String, value : String) : Conn#

Add a response header. Returns updated conn.

fnquery_stringquery_string(conn : Conn) : String#

Returns the raw query string, e.g. \

fnregister_after_sendregister_after_send(conn : Conn, hook_key : String) : Conn#

Register a named after-send hook. The hook is identified by a string key that the server resolves to a function.

Multiple hooks can be registered; they are stored as a comma-separated list.

    Conn.register_after_send(conn, "session_commit")
fnreq_bodyreq_body(conn : Conn) : String#

Returns the raw request body as a string.

fnreq_headersreq_headers(conn : Conn) : List(Header)#

Returns all request headers as a list of Header(name, value) values.

fnresp_bodyresp_body(conn : Conn) : String#

Returns the response body string accumulated so far.

fnresp_headersresp_headers(conn : Conn) : List(Header)#

Returns all response headers accumulated so far.

fnsend_respsend_resp(conn : Conn, status : Int, body : String) : Conn#

Set the response status and body, and mark the conn as halted. After send_resp the pipeline stops processing further plugs.

fnstatusstatus(conn : Conn) : Int#

Returns the current response status code (0 means not yet set).