Http2FrameCodec
Defined in: packages/format-http/src/h2/http2-frame-codec.ts:96
The HTTP/2 frame layer (RFC 9113 §4 and §6) for one end of a connection, with the HPACK state of both directions.
Decoding checks every per-frame rule — lengths, stream-zero rules, padding, setting ranges — and reassembles a HEADERS (or PUSH_PROMISE) frame and its CONTINUATIONs into one value with decoded fields; a frame of another kind in between is a connection error. DATA payloads come inline (see Http2DataFrame). PRIORITY frames and unknown types are validated as far as RFC 9113 requires and skipped.
A violation is reported as an error carrying an Http2Error. A
stream error consumes its frame and decoding goes on; after a connection
error everything is discarded, and the endpoint must send GOAWAY with its
code and close.
Encoding writes one frame as buffers for one vectored write, a HEADERS frame followed by as many CONTINUATIONs as the peer’s frame size requires. Frames must be sent in the order they were encoded: HPACK state changes with every field block.
Memory: the receive buffer holds at most one frame (maxFrameSize), plus one
field block being reassembled (maxFieldBlockSize).
Implements
Section titled “Implements”Codec<Http2Frame,Http2OutboundFrame>
Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new Http2FrameCodec(
options):Http2FrameCodec
Defined in: packages/format-http/src/h2/http2-frame-codec.ts:103
Parameters
Section titled “Parameters”options
Section titled “options”Returns
Section titled “Returns”Http2FrameCodec
Methods
Section titled “Methods”decode()
Section titled “decode()”decode(
view):DecodeResult<Http2Frame>
Defined in: packages/format-http/src/h2/http2-frame-codec.ts:128
Attempt to decode one value from the front of view.
view is a window into the driver’s buffer and is invalidated as soon as
this call returns. Copy anything retained in the returned value.
Parameters
Section titled “Parameters”Uint8Array
Returns
Section titled “Returns”DecodeResult<Http2Frame>
Implementation of
Section titled “Implementation of”Codec.decode
encode()
Section titled “encode()”encode(
frame): readonlyUint8Array<ArrayBufferLike>[]
Defined in: packages/format-http/src/h2/http2-frame-codec.ts:156
Parameters
Section titled “Parameters”Returns
Section titled “Returns”readonly Uint8Array<ArrayBufferLike>[]
Throws
Section titled “Throws”When a DATA payload exceeds the peer’s frame size, a PING payload is not 8 octets, or a value does not fit its field.
Throws
Section titled “Throws”When a field name or value is not Latin-1.
Implementation of
Section titled “Implementation of”Codec.encode
reset()
Section titled “reset()”reset():
void
Defined in: packages/format-http/src/h2/http2-frame-codec.ts:219
Discard accumulated decode state ahead of a protocol mode switch.
Returns
Section titled “Returns”void
Implementation of
Section titled “Implementation of”Codec.reset
setPeerHeaderTableSize()
Section titled “setPeerHeaderTableSize()”setPeerHeaderTableSize(
size):void
Defined in: packages/format-http/src/h2/http2-frame-codec.ts:124
Apply the peer’s SETTINGS_HEADER_TABLE_SIZE. The encoder uses at most
4096 octets whatever the peer allows, which bounds its own memory.
Parameters
Section titled “Parameters”number
Returns
Section titled “Returns”void
setPeerMaxFrameSize()
Section titled “setPeerMaxFrameSize()”setPeerMaxFrameSize(
size):void
Defined in: packages/format-http/src/h2/http2-frame-codec.ts:116
Apply the peer’s SETTINGS_MAX_FRAME_SIZE to frames encoded from now on.
Parameters
Section titled “Parameters”number
Returns
Section titled “Returns”void