std/http/client
std/http/src/client.trb
The HTTP/1.1 client: get, post and send answer a task of a Response whose Body is a stream
(docs/design/NETWORK.md section 7), over TCP for http and over TLS for https. The free functions open one
connection per request and close it with its response; a Client keeps connections alive and follows redirects
(./pool). What to reach is a Uri (docs/design/URI.md section 10): the text was read once, where it entered the
program, and nothing here takes a URL apart by hand.
fn get
fn get(url: Uri, headers: Headers = Headers()): Task<Result<Response, HttpError>>
http.get(url).await()?: a GET of url. A status that is not a success is a Response too - status says what
it is - and no redirect is followed.
fn post
fn post(url: Uri, body: Body, headers: Headers = Headers()): Task<Result<Response, HttpError>>
http.post(url, Body.from(text)).await()? - the body may be a stream, so an upload is not held in memory.
fn send
fn send(method: Method, url: Uri, headers: Headers = Headers(), body: Body = Body.empty(), tls: TlsSettings = TlsSettings()): Task<Result<Response, HttpError>>
A request of any method on a connection of its own: connects to the host of url - straight to an IP literal,
through the resolver for a name - writes the request - with Content-Length where the body's length is known, in
chunks where it is not - and answers the response once its head arrived. The body of the response is read from the
connection as the program pulls it, and the connection closes with the response. The fragment of url is not sent,
and no redirect is followed: a Client (pool.trb) keeps connections alive and follows redirects.
Errors
HttpErrorthat isunsupportedfor a URI this client does not reach (a scheme other thanhttpandhttps, an empty host, user information), and for a connection that fails, a certificate that is not the host's (itscause()is theNetworkErrorthatisCertificateRejected()), and a response that breaks HTTP/1.1.