Skip to content

Http1ServerCodec

Defined in: packages/format-http/src/h1/http1-server-codec.ts:48

The server side of an HTTP/1.x connection: decodes requests, encodes responses.

Decoding yields an Http1Request per request, whose body — when it has one — follows as the value’s streamed body (length framing) or as Http1Chunk values ended by Http1Trailers (chunked).

After a request asking to leave HTTP (an Upgrade field, or CONNECT), decoding holds: the bytes that follow may already belong to the next protocol. Call release when declining the switch to resume.

After a malformed request, decoding reports one error carrying an Http1MessageError, then discards everything: the server should answer with the error’s status and close the connection.

Encoding writes an Http1ResponseHead, one Http1ChunkData, or the last chunk and trailers (Http1Trailers), as buffers ready for one vectored write. The caller chooses the framing through the fields it sets.

Decoding a head is O(n) time and memory in its size.

new Http1ServerCodec(options): Http1ServerCodec

Defined in: packages/format-http/src/h1/http1-server-codec.ts:57

Http1CodecOptions

Http1ServerCodec

decode(view): DecodeResult<Http1ServerInbound>

Defined in: packages/format-http/src/h1/http1-server-codec.ts:61

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<Http1ServerInbound>

Codec.decode


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

Defined in: packages/format-http/src/h1/http1-server-codec.ts:79

Encode a value into one or more output chunks.

Returning an array defers concatenation to a vectored write, so a length-prefixed protocol can emit [header, payload] without copying the payload.

Http1ServerOutbound

readonly Uint8Array<ArrayBufferLike>[]

Codec.encode


release(): void

Defined in: packages/format-http/src/h1/http1-server-codec.ts:84

Resume decoding after declining the protocol switch a request asked for.

void


reset(): void

Defined in: packages/format-http/src/h1/http1-server-codec.ts:91

Discard accumulated decode state ahead of a protocol mode switch.

void

Codec.reset