A minimal HTTP/1.1 request parser and response builder shared by the Riak and etcd handlers (both of which speak HTTP over TCP).
It only implements the slice of HTTP these fake services need: a request line,
headers, and a Content-Length-delimited body. Chunked transfer encoding is
not supported.
Summary
Functions
Parse a single request out of buffer.
Parse an application/x-www-form-urlencoded body into a map.
Build an HTTP/1.1 response. Content-Length is always set; extra headers can
be supplied as a keyword list.
Percent-decode a URI component (e.g. %2F -> /, + -> space).
Types
Functions
Parse a single request out of buffer.
Returns {:ok, request, rest} when a full request (headers + declared body)
is present, :incomplete when more bytes are needed, or :error when the
request is malformed (e.g. a garbage Content-Length) and the connection
should be dropped — without a valid length the request boundary is unknowable.
Parse an application/x-www-form-urlencoded body into a map.
@spec response(non_neg_integer(), String.t(), iodata(), keyword()) :: iodata()
Build an HTTP/1.1 response. Content-Length is always set; extra headers can
be supplied as a keyword list.
Percent-decode a URI component (e.g. %2F -> /, + -> space).