Represents an HTTP connection in Passby.
This struct and its helper functions provide a familiar, lightweight API
compatible with Plug.Conn and Bypass handler functions without requiring
Plug as a dependency.
Summary
Functions
Fetches query parameters from the query string and stores them on the conn.
Gets the values of the specified request header.
Sets or adds a response header.
Sets the response status and body without immediately transmitting it.
Sends the response configured in the connection struct over the socket.
Sends the response with the given status and body over the underlying socket.
Types
@type t() :: %Passby.Conn{ adapter: {module(), any()}, host: String.t(), method: String.t(), params: params(), path_info: [String.t()], path_params: params(), port: :inet.port_number() | nil, query_params: params(), query_string: String.t(), req_body: binary(), req_headers: [{String.t(), String.t()}], request_path: String.t(), resp_body: binary() | nil, resp_headers: [{String.t(), String.t()}], state: :unset | :set | :sent, status: integer() | nil }
Functions
Fetches query parameters from the query string and stores them on the conn.
Populates conn.query_params with the decoded query string and merges the
result into conn.params. Any params already present on the conn (for
example path params) take precedence over query params on key conflicts.
Bracket notation is decoded the same way Plug.Conn.Query decodes it, so
"filter[name]=Manuel" becomes %{"filter" => %{"name" => "Manuel"}}.
The optional second argument is accepted for Plug.Conn.fetch_query_params/2
compatibility and is currently ignored.
Examples
iex> conn = %Passby.Conn{query_string: "filter[name]=Manuel"}
iex> conn = Passby.Conn.fetch_query_params(conn)
iex> conn.query_params
%{"filter" => %{"name" => "Manuel"}}
iex> conn.params
%{"filter" => %{"name" => "Manuel"}}
Gets the values of the specified request header.
Header names are case-insensitive. Returns a list of string values matching the header name (or an empty list if not present).
Examples
iex> conn = %Passby.Conn{req_headers: [{"soapaction", "sessionOpen"}]}
iex> Passby.Conn.get_req_header(conn, "SoapAction")
["sessionOpen"]
Sets or adds a response header.
Examples
iex> conn = %Passby.Conn{}
iex> conn = Passby.Conn.put_resp_header(conn, "content-type", "application/json")
iex> conn.resp_headers
[{"content-type", "application/json"}]
Sets the response status and body without immediately transmitting it.
Examples
iex> conn = %Passby.Conn{}
iex> conn = Passby.Conn.resp(conn, 200, "Hello World")
iex> conn.status
200
iex> conn.resp_body
"Hello World"
Sends the response configured in the connection struct over the socket.
Sends the response with the given status and body over the underlying socket.
If no status and body are passed, it sends the response configured in the struct.