Net.HTTP.Payload

lib/Net/HTTP/Payload.gob

A request body as the client sends it: whether it can be sent again, and a function that makes the Stream to send each time. The client sends a ClientRequest Payload; the Body instances (Net.HTTP.Body) make one with text, bytes, file, incoming and stream.

Sent again. A String and a Buffer are held, and a File is read from offset 0 by readAt each time it is sent, so it never depends on the file's position: each of these can be sent again. An Incoming and a Stream are read as they are written, once, and cannot. The client's retry and redirect rules send a request again only when its body is replayable.

The length is sent as Content-Length: a String's and a Buffer's size, the size stat returns for a File when the request is sent, an Incoming's declared length, and a Stream's own. A body with none goes chunked. A file that then grows or shrinks while it is written fails the request (Overrun or Truncated) rather than sending other bytes than the length declared.

type Payload

open is called once per send, before the head is written, and the stream it returns is sent once.

fun replayable : fun(Payload) -> Bool

Returns whether the body can be sent again.

fun awaitsContinue : fun(Payload) -> Bool

Returns whether the body is a received one whose sender waits for a 100 Continue that reading it will send, so that the request carrying it should ask its own server for one first.

fun open : fun(Payload) -> Either HTTPError Stream

Returns the stream that sends the body this time, or why there is none: a file that cannot be measured.

fun text : fun(String) -> Payload

Returns s's UTF-8 bytes as a body.

fun bytes : fun(Buffer) -> Payload

Returns b's window, as it is now, as a body. The buffer is never consumed, so a send again sends the same bytes.

fun file : [CanRead m] fun(File m) -> Payload

Returns f's contents as a body, read from offset 0 each time it is sent.

fun incoming : fun(Incoming) -> Payload

Returns a body that arrived, passed on as it is read: the length its framing declared, if any, the bytes as they come, with no limit of their own, and its trailers. It can be sent once.

fun stream : fun(Stream) -> Payload

Returns s as a body. It can be sent once.