std/http
HTTP/1.1, client and server, in TorbScript over std/network (docs/design/NETWORK.md sections 6 to 9).
The client: get, post and send take the Uri to reach and answer a task of a Response, whose Body is a stream - a response of any
size can be piped into a file or read chunk by chunk, and the convenience that covers nine cases out of ten sits on
top of it (body.text(), body.json<User>(), each with a limit).
The server: Server.listen with a Handler, a function from a Request to a task of a Response; every connection
is a task, and the parser is strict about everything request smuggling lives on.
Needs the network capability inside a sandboxed script; https is TLS over std/tls.
Modules
std/http/clientThe HTTP/1.1 client:get,postandsendanswer a task of aResponsewhoseBodyis a stream (docs/design/NETWORK.md section 7), over TCP forhttpand over TLS forhttps.std/http/errorHttpError: what every operation ofstd/httpfails with - the client's, the server's and the parser's - as one wrapper type, so a new kind of failure is never a breaking change (see "Algebraic Data Types and Pattern Matching" in CONCEPT.md).std/http/messageThe parts of an HTTP message:Method,Status,Headers, theBodythat is a stream, and the two messages,RequestandResponse(docs/design/NETWORK.md section 6).std/http/poolThe client that keeps connections: a [Client] holds a pool of kept-alive connections per origin, at mostmaximumConnectionsof them open to one origin at a time, and follows redirects as its [RedirectPolicy] allows (docs/design/NETWORK.md section 7, slice 7).std/http/serverThe HTTP/1.1 server: a listener, a handler that is a function from a request to a task of a response, an accept loop per worker on the one listening socket, and one task per connection that serves its requests one after another (docs/design/NETWORK.md sections 4 and 8).
Everything
- type
BodyThe bytes of a request or a response, as a stream that is read once. - extend
Body with From<String>Body.from("hello")- the text as UTF-8. - extend
Body with From<Bytes>Body.from(bytes)- one chunk, already in memory. - type
ClientAn HTTP client that keeps its connections alive between requests, one pool per origin, and follows redirects. - fn
gethttp.get(url).await()?: aGETofurl. - alias
HandlerWhat serves a request: a function from the request to a task of the response. - type
HeadersThe fields of a head, in the order they arrived. - extend
Headers with From<Map<String, String>>Headers.from(["Accept": "application/json"]): the entries of a map, in its order. - type
HttpErrorWhat went wrong with a request or a response. - extend
HttpError with From<Utf8Error>What makesbody.lines()work: a stage over bytes, so it needs nothing of HTTP. - extend
HttpError with From<JsonError>...and what makesbody.through(Json.items<User>()).checked()work without naming a second failure type. - extend
HttpError with From<NetworkError>A failure of the connection under a message is the message's failure. - type
MethodAn HTTP method: a case per method RFC 9110 registers,Query(RFC 10008) and WebDAV'sSearch(RFC 5323), andOtherfor the rest - the set is open (a WebDAV server meetsPROPFIND), so a router matches on the cases and still sees every method. - fn
posthttp.post(url, Body.from(text)).await()?- the body may be a stream, so an upload is not held in memory. - type
RedirectPolicyWhat a [Client] does with a redirect - a301,302,303,307or308with aLocationfield. - type
RequestA request: what a client sends and what a server's handler is handed. - type
ResponseWhat came back from a server, or what a handler answers. - fn
sendA request of any method on a connection of its own: connects to the host ofurl- straight to an IP literal, through the resolver for a name - writes the request - withContent-Lengthwhere the body's length is known, in chunks where it is not - and answers the response once its head arrived. - type
ServerAn HTTP/1.1 server. - type
ServerLimitsWhat a server allows a client, each against an attack of its own. - type
StatusAn HTTP status: a capsule over its code, from 100 to 599, with the common ones as constants.