Net.HTTP.H1.Body
An HTTP/1 message body as a Read: the bytes after a head, decoded from
their framing, ending exactly where the message ends, so that what follows
is the next message.
ContentLength(n):nbytes. A stream that ends first isTruncated.Chunked: chunks, eachchunk-size [ chunk-ext ] CRLF data CRLF, then the last chunk and the trailers.UntilClose: everything until the stream ends.NoBody: nothing.
A chunk is read as strictly as a head. The size is hex digits only (no
+, -, 0x or whitespace), at most 16 of them, and overflow-checked.
The whole chunk-size line, extensions included, is at most
chunkLineBytes, which bounds the bytes a peer can send that no reader
looks at. Extensions must be well-formed, though their meaning is ignored.
The data must be followed by exactly CRLF. The trailers are field lines as
a head's are, at most trailerBytes of them, and may not hold a reserved
field. Any of these refused is a BadMessage, and the body fails from
then on: its framing is lost, so the connection cannot be reused.
The limit a program reads under is Net.HTTP.Incoming's, applied to
what this reader returns; incoming wraps a body as one.
Returns the body framed by framing that starts at what input holds.
Makes hook run once, just before the body's first read from the stream,
and fail that read if it fails.
This is the seam for 100 Continue. A client that sent
Expect: 100-continue waits for it before sending the body, so the server
sets a hook that writes it. Net.HTTP.Incoming checks a declared length
against the program's limit before it reads at all, so a body refused as
too large never runs the hook, and the client is refused before it sends
a byte.
Returns the body's length if its framing declared one.
Whether the body has been read to its end.
Returns the trailers of a chunked body that has been read to its end, and no fields for any other.
Whether a connection can carry another message once this body is behind
it: Reusable when the body has been read to its end, MustClose when it
cannot be, or not cheaply enough.
Reads and discards what is left of b, if that is cheap, and returns
whether the connection can be reused. RFC 9112 ยง9.3: a server must read a
whole body or close the connection, or the rest is read as the next
message; a client reusing a pooled connection is in the same place.
- Read to its end already:
Reusable. - A declared remainder: discarded if it is at most
drainBytes, elseMustCloseat once, without reading. Skipping gigabytes to save one handshake is a bad trade. - Chunked: discarded until it ends, or until
drainByteshave been, and thenMustClose. - Until the stream closes:
MustClose. - A body whose first-read hook has not run:
MustClose. That is a client still waiting for100 Continue, which may never send the body, or may send it later, after the next message has been looked for. - A body that already failed:
MustClose.
The server and the client both end a message with this, and close the
connection, staged as they see fit, on MustClose or on an error.
Returns b as the Incoming a program reads, with the stream's errors
made HTTPErrors by lift.