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
| Type | Method and description |
|---|---|
| readLine(inp : Wire, spill : i8[], have : i64) : LineRead Pull one CRLF-terminated line out of spill, reading more when it isnot there yet. Bounded by maxStartLine so a peer that never sends aterminator 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 thatends 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
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.
inp connected stream to read fromspill bytes already read past the previous linehave valid byte count in spillIOException on a line longer than maxStartLine, or on atransport 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
| Type | Method and description |
|---|---|
| constructor(line : string, spill : i8[], spillLen : i64, atEof : bool) |