Axle v0.22.0
Package

std/net/httpline

std/net/httpline — one CRLF-terminated line off a transport, and the
bytes that came with it.

Entry: a Wire and whatever a previous read left over.
Exit: the line, the new leftover, and whether the stream ended before a
terminator arrived.

That last flag is the whole reason this is its own module rather than a
helper inside the chunked reader. A close before a CRLF means opposite
things in the two places a line is read — a truncated message inside a
body, a conforming ending after the last chunk — and only the caller
knows which it is standing in. Reporting the fact instead of deciding it
is what lets one reader serve both.

Free functions

TypeMethod and description
LineRead
readLine(inp : Wire, spill : i8[], have : i64) : LineRead Pull one CRLF-terminated line out of spill, reading more when it is
not there yet. Bounded by maxStartLine so a peer that never sends a
terminator cannot make this grow without end.

A peer that closes before a terminator arrives is reported, not
refused: the result carries atEof and the caller decides. A read that
ends mid-message is a truncated message; the same read after the last
chunk is a conforming end, and a reader that threw could not tell the
caller apart from the stream.

The scan resumes one byte behind where the last one stopped rather than
restarting at zero — one back because a CRLF may straddle two reads.
Restarting would re-walk the whole buffer per read, and a peer choosing
how many bytes to send at a time is choosing how many times that
happens: a line delivered one byte at a time would cost the square of
its length, under this function's own bound, for free.

Method detail

#readLine

readLine(inp : Wire, spill : i8[], have : i64) : LineRead ! IOException

Pull one CRLF-terminated line out of spill, reading more when it is
not there yet. Bounded by maxStartLine so a peer that never sends a
terminator cannot make this grow without end.

A peer that closes before a terminator arrives is reported, not
refused: the result carries atEof and the caller decides. A read that
ends mid-message is a truncated message; the same read after the last
chunk is a conforming end, and a reader that threw could not tell the
caller apart from the stream.

The scan resumes one byte behind where the last one stopped rather than
restarting at zero — one back because a CRLF may straddle two reads.
Restarting would re-walk the whole buffer per read, and a peer choosing
how many bytes to send at a time is choosing how many times that
happens: a line delivered one byte at a time would cost the square of
its length, under this function's own bound, for free.

Parameters
inp connected stream to read from
spill bytes already read past the previous line
have valid byte count in spill
Throws
IOException on a line longer than maxStartLine, or on a
transport failure the stream itself reports.

C class LineRead

One line, plus the reader's position: what was read past it, and
whether the stream ended first.

Constructors

Method detail

#constructor

constructor(line : string, spill : i8[], spillLen : i64, atEof : bool)