nhttp_h3_frame (nhttp_lib v1.0.0)

View Source

HTTP/3 binary frame encoding and decoding.

Implements RFC 9114 Section 7. Each HTTP/3 frame consists of:

Type (varint) | Length (varint) | Payload (Length bytes)

Unlike HTTP/2's fixed 9-byte header, HTTP/3 uses QUIC variable-length integers for both type and length fields.

Frame types 0x02, 0x06, 0x08, 0x09 are forbidden in HTTP/3 (reserved from HTTP/2). Receiving them is a connection error (H3_FRAME_UNEXPECTED).

Unknown frame types in the grease range (0x1f * N + 0x21) must be silently ignored. All other unknown types must also be ignored per RFC 9114 Section 9.

Summary

Functions

Encode a CANCEL_PUSH frame.

Encode a DATA frame.

Decode a single HTTP/3 frame. Returns the unparsed tail on success.

Encode a GOAWAY frame.

Encode a HEADERS frame (payload is raw QPACK-encoded bytes).

Encode a MAX_PUSH_ID frame.

Encode a PUSH_PROMISE frame.

Encode a SETTINGS frame.

Types

decode_error()

-type decode_error() :: h3_frame_unexpected | h3_frame_error | h3_settings_error.

decode_result()

-type decode_result() :: {ok, t(), Rest :: binary()} | {more, pos_integer()} | {error, decode_error()}.

h3_settings()

-type h3_settings() ::
          #{max_field_section_size => non_neg_integer() | infinity,
            qpack_max_table_capacity => non_neg_integer(),
            qpack_blocked_streams => non_neg_integer(),
            enable_connect_protocol => boolean()}.

t()

-type t() ::
          {data, binary()} |
          {headers, binary()} |
          {cancel_push, PushId :: non_neg_integer()} |
          {settings, h3_settings()} |
          {push_promise, PushId :: non_neg_integer(), FieldSection :: binary()} |
          {goaway, Id :: non_neg_integer()} |
          {max_push_id, PushId :: non_neg_integer()} |
          {unknown, Type :: non_neg_integer(), Payload :: binary()}.

Functions

cancel_push(PushId)

-spec cancel_push(non_neg_integer()) -> {ok, iodata()}.

Encode a CANCEL_PUSH frame.

data(Payload)

-spec data(iodata()) -> {ok, iodata()}.

Encode a DATA frame.

decode(Bin)

-spec decode(binary()) -> decode_result().

Decode a single HTTP/3 frame. Returns the unparsed tail on success.

goaway(Id)

-spec goaway(non_neg_integer()) -> {ok, iodata()}.

Encode a GOAWAY frame.

headers(FieldSection)

-spec headers(iodata()) -> {ok, iodata()}.

Encode a HEADERS frame (payload is raw QPACK-encoded bytes).

max_push_id(PushId)

-spec max_push_id(non_neg_integer()) -> {ok, iodata()}.

Encode a MAX_PUSH_ID frame.

push_promise(PushId, FieldSection)

-spec push_promise(non_neg_integer(), iodata()) -> {ok, iodata()}.

Encode a PUSH_PROMISE frame.

settings(Settings)

-spec settings(h3_settings()) -> {ok, iodata()}.

Encode a SETTINGS frame.