Net.HTTP.Incoming

lib/Net/HTTP/Incoming.gob

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.

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.

type Incoming
fun incoming : fun(AnyRead HTTPError, Option Int, fun() -> Option Headers, fun() -> Bool) -> Incoming

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.

fun awaitsContinue : fun(Incoming) -> Bool

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.

fun declaredLength : fun(Incoming) -> Option Int

Returns the body's declared length, if its framing gave one.

fun trailers : fun(Incoming) -> Option Headers

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.

type BodyRead

A Read over a body, under a limit.

fun limited : fun(Incoming, Int) -> BodyRead

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.

fun unbounded : fun(Incoming) -> BodyRead

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.

fun receive : [FromHTTP e] fun(Incoming, Int) -> Either e Buffer

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.

instance Read BodyRead