Skip to content

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).

new Http2FrameCodec(options): Http2FrameCodec

Defined in: packages/format-http/src/h2/http2-frame-codec.ts:103

Http2FrameCodecOptions

Http2FrameCodec

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.

Uint8Array

DecodeResult<Http2Frame>

Codec.decode


encode(frame): readonly Uint8Array<ArrayBufferLike>[]

Defined in: packages/format-http/src/h2/http2-frame-codec.ts:156

Http2OutboundFrame

readonly Uint8Array<ArrayBufferLike>[]

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.

When a field name or value is not Latin-1.

Codec.encode


reset(): void

Defined in: packages/format-http/src/h2/http2-frame-codec.ts:219

Discard accumulated decode state ahead of a protocol mode switch.

void

Codec.reset


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.

number

void


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.

number

void