HttpStreamParser class

An incremental parser for one direction of an HTTP/1.x connection.

Feed the stream through add in order; each call returns the events the new bytes completed. Memory stays bounded: only an incomplete head (or chunk-size line) is buffered, never a body, and a head larger than maxHeadBytes ends framing.

Body framing follows RFC 9112 §6: Transfer-Encoding: chunked (extensions and trailers included), Content-Length, or — for responses only — the connection closing (call close). A response parser must be told the method of each request it answers (expectResponseTo), because a HEAD response has no body and a CONNECT success switches protocols; interim 1xx responses do not consume the expectation.

The parser switches to pass-through (isPassthrough) after a protocol switch (101, a successful CONNECT, or an upgrade request), on an ambiguous body length, on input that is not HTTP/1.x, and on an oversized head.

Constructors

HttpStreamParser.requests({int maxHeadBytes = 64 * 1024})
Creates a parser for client→server request bytes.
HttpStreamParser.responses({int maxHeadBytes = 64 * 1024})
Creates a parser for server→client response bytes.

Properties

hashCode → int
The hash code for this object.
no setterinherited
isIdle → bool
Whether the parser is between messages (nothing partial is pending).
no setter
isPassthrough → bool
Whether the parser has stopped framing and reports raw pass-through.
no setter
isReadingHead → bool
Whether part of a head has arrived but not all of it — the window a client-header timeout measures.
no setter
isResponse → bool
Whether this parser reads responses (otherwise requests).
final
maxHeadBytes → int
The largest head (or chunk line) buffered before giving up framing.
final
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited

Methods

add(Uint8List data) → List<HttpStreamEvent>
Consumes the next data of the stream and returns the completed events.
close() → List<HttpStreamEvent>
Signals the end of the stream. Completes a close-delimited response body, and reports any incomplete buffered bytes as pass-through.
expectResponseTo(String method) → void
Records that the next unanswered request used method (response parsers only). Responses are matched to requests in order.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() → String
A string representation of this object.
inherited

Operators

operator ==(Object other) → bool
The equality operator.
inherited

Static Methods

parseRequestHead(String text) → HttpRequestHead?
Parses a request head, or null when it is not well-formed HTTP/1.x.
parseResponseHead(String text) → HttpResponseHead?
Parses a response head, or null when it is not well-formed HTTP/1.x.