Net.HTTP.Incoming
A message body that has arrived and not been read: a request's, for a server's handler, or a response's, for a client's callback.
(POST(body), "/orders") -> {
let bytes = receive(body, 65536)?
...
}
The limit is part of reaching the bytes. An Incoming gives its bytes
only through receive(b, atMost), which reads the whole body into a buffer,
limited(b, atMost), a Read over it, or unbounded(b), a Read with no
limit, conspicuously named, for a proxy that streams a body on. No default
limit exists to forget, and a handler that never reads a body never thinks
about one.
- A body whose declared length is over
atMostisTooLargeat once, before a byte is read, so a server can answer 413 and a client waiting for100 Continueis refused before it sends anything. - A body without a declared length (chunked) is counted as it arrives, and
is
TooLargeat the first byte pastatMost. - A body is taken once. A second
receive,limitedorunboundedfails withConsumed: otherwise a second limit would start counting again where the first stopped.
Trailers are fields sent after a chunked body, such as a checksum or
gRPC's status. trailers(b) returns them once the body has been read to
its end, and None before then.
An Incoming hides the connection under it, TCP or TLS, behind one
indirect call per read, so a handler takes no transport parameter. Its
errors are HTTPErrors; receive lifts them into the caller's error type
through FromHTTP.
Returns the body source reads, whose framing declared declared bytes,
or None if it declared no length. trailers returns the trailers once
source has ended, and None until then. awaitsContinue returns True
while the body's sender waits for a 100 Continue that the body's first
read sends. A codec makes one from what it read; a test makes one to give
a handler a body.
Returns whether the body's sender is waiting for a 100 Continue, which
reading the body sends. A proxy that relays the body asks its upstream
for a 100 first, and reads the body only once it arrives, so that an
upstream refusal reaches the sender before it sends a byte.
Returns the body's declared length, if its framing gave one.
Returns the fields that followed the body, once it has been read to its
end: no fields for a body that was not chunked, or whose sender added none.
Returns None while the body has not ended.
A Read over a body, under a limit.
Returns a Read over the body that fails with TooLarge past atMost
bytes: at its first read if the declared length is over it, or else at
the first byte past it. Panics if atMost is negative.
Returns a Read over the body with no limit at all. For a program that
passes a body on as it arrives, and bounds it some other way.
Returns the whole body, at most atMost bytes, in a buffer of its own:
one allocation of the declared length where there is one. A longer body
is TooLarge.