h1_message (h1 v0.2.0)
View SourceHTTP/1.1 message encoder.
Builds iolists suitable for direct use with gen_tcp:send / ssl:send. Covers: request line, status line, header block, chunked body frames, trailer block. Also helpers for Content-Length / Transfer-Encoding auto-selection.
Based on livery_resp.erl (enki-multimedia) with additions for client-side request building.
Summary
Functions
Decide how to frame an outgoing message body.
Assemble a message from a head line, headers and body. Adds Content-Length when missing and body is not chunked.
Build a full request: request line + headers + body.
Build a full response: status line + headers + body. Auto-adds Content-Length when the body is fully known.
Types
-type version() :: {non_neg_integer(), non_neg_integer()}.
Functions
-spec choose_framing(iodata() | chunked | no_body, headers()) -> {content_length, non_neg_integer(), headers()} | {chunked, headers()} | {no_body, headers()}.
Decide how to frame an outgoing message body.
Returns {content_length, N, Headers} when Content-Length will be used (body is a fully-known binary/iodata), {chunked, Headers} when caller opted into streaming, or {no_body, Headers} for bodyless messages.
Assemble a message from a head line, headers and body. Adds Content-Length when missing and body is not chunked.
-spec encode_last_chunk() -> binary().
Build a full request: request line + headers + body.
-spec encode_response(non_neg_integer(), headers(), iodata()) -> iodata().
Build a full response: status line + headers + body. Auto-adds Content-Length when the body is fully known.
-spec encode_response(non_neg_integer(), headers(), iodata(), version()) -> iodata().
-spec status_line(non_neg_integer(), version()) -> iodata().
-spec status_line(non_neg_integer(), binary(), version()) -> iodata().
-spec status_text(non_neg_integer()) -> binary().