~/bend-docscommunity

src/client.bend relies on unsafe/foreign

raw source on the hub · import emerging-ezhttp@0.16.0.0/src/client.bend as Client

ezhttp/src/client: fetch a URL. URL and HTTP parsing joined to the wire effect. Answers a structured Response (status + headers + body), not a hub-style "0\n…" string contract.

8 imports
import Base
import ./url.bend as Url
import ./http.bend as Http
import ./body.bend as Body
import ./wire.bend as Wire
import ./wirespec.bend as Spec
import ./redirect.bend as Redirect
import ./auth.bend as Auth

Types

type Response source · line 15 · raw

Data

structured client result: transport/parse error, or an HTTP response with its status line's reason phrase (SPEC.md HTTP-CLI-11)

Definitions

def from.reply source · line 22 · raw

@r:0x1bc4d92e7c1f4dd1a49d87ad449b730b/src/http.Reply -> @reason:String -> Response

a torn or successful HTTP parse as a client Response, with the reason phrase read from the same text

def http.heard source · line 32 · raw

@+method:String -> @+raw:String -> Response

an exchange's answer as a client Response, read by the request's method (wirespec.bend wire.heard: interim 1xx heads skipped, no body for HEAD, 1xx, 204 or 304; a failed exchange keeps its reason)

def http.send source · line 37 · raw

@ex:0x1bc4d92e7c1f4dd1a49d87ad449b730b/src/wirespec.Exchange -> @tail:List<&2, U32> -> IO(Response)

an exchange as wirespec.bend wrote it, with the body's tail of octets: sent and read by its own method, or the URL's reason

def http.loc source · line 47 · raw

@method:String -> @l:0x1bc4d92e7c1f4dd1a49d87ad449b730b/src/url.Loc -> @headers:List<&2, 0x1bc4d92e7c1f4dd1a49d87ad449b730b/src/http.Header> -> @+body:0x1bc4d92e7c1f4dd1a49d87ad449b730b/src/body.Body -> IO(Response)

a URL that came apart (or not) into an HTTP exchange with this body

def http.send.timed source · line 54 · raw

@ms:U32 -> @ex:0x1bc4d92e7c1f4dd1a49d87ad449b730b/src/wirespec.Exchange -> @tail:List<&2, U32> -> IO(Response)

an exchange as wirespec.bend wrote it, bounded by a timeout, sent and read by its own method

def client.timed source · line 67 · raw

@method:String -> @url:String -> @headers:List<&2, 0x1bc4d92e7c1f4dd1a49d87ad449b730b/src/http.Header> -> @+body:0x1bc4d92e7c1f4dd1a49d87ad449b730b/src/body.Body -> @ms:U32 -> IO(Response)

a request with this method, headers and body, bounded by a timeout in milliseconds

def client.get.timed source · line 73 · raw

@url:String -> @headers:List<&2, 0x1bc4d92e7c1f4dd1a49d87ad449b730b/src/http.Header> -> @ms:U32 -> IO(Response)

GET bounded by a timeout in milliseconds

def client.hop source · line 78 · raw

@left:Nat -> @url:String -> @r:Response -> 0x1bc4d92e7c1f4dd1a49d87ad449b730b/src/redirect.Hop

the next hop after a response (redirect.bend); a failed exchange stops

def client.after source · line 86 · raw

@hop:0x1bc4d92e7c1f4dd1a49d87ad449b730b/src/redirect.Hop -> @r:Response -> @go:(@_:String -> IO(Response)) -> IO(Response)

a response, or the GET its hop asks for

def client.follow source · line 97 · raw

@+left:Nat -> @+url:String -> @+headers:List<&2, 0x1bc4d92e7c1f4dd1a49d87ad449b730b/src/http.Header> -> @body:0x1bc4d92e7c1f4dd1a49d87ad449b730b/src/body.Body -> @+ms:U32 -> IO(Response)

GET, following redirects while left hops remain; body goes with this hop only. The answer is the last response, which is a redirect only when the hops ran out or its Location is not one redirect.bend follows

def client.request.go source · line 109 · raw

@go:Bool -> @method:String -> @url:String -> @headers:List<&2, 0x1bc4d92e7c1f4dd1a49d87ad449b730b/src/http.Header> -> @body:0x1bc4d92e7c1f4dd1a49d87ad449b730b/src/body.Body -> @ms:U32 -> IO(Response)

a request once it is known whether it follows redirects

def client.request.opts source · line 120 · raw

@+method:String -> @url:String -> @headers:List<&2, 0x1bc4d92e7c1f4dd1a49d87ad449b730b/src/http.Header> -> @body:0x1bc4d92e7c1f4dd1a49d87ad449b730b/src/body.Body -> @ms:U32 -> @follow:Bool -> IO(Response)

a request with a method, headers, body and timeout; it follows redirects when follow is set and the method is GET (redirect.bend redirect.follows), and answers its first response otherwise

def client.get.opts source · line 127 · raw

@url:String -> @headers:List<&2, 0x1bc4d92e7c1f4dd1a49d87ad449b730b/src/http.Header> -> @ms:U32 -> @follow:Bool -> IO(Response)

GET with headers and a timeout, following redirects when follow is set

def client.timed_out source · line 132 · raw

@r:Response -> Bool

whether a response is the failure of an exchange that ran out of time

def client.get source · line 140 · raw

@url:String -> @headers:List<&2, 0x1bc4d92e7c1f4dd1a49d87ad449b730b/src/http.Header> -> IO(Response)

GET

def client.head source · line 144 · raw

@url:String -> @headers:List<&2, 0x1bc4d92e7c1f4dd1a49d87ad449b730b/src/http.Header> -> IO(Response)

HEAD (RFC 9110 §9.3.2)

def client.post source · line 148 · raw

@url:String -> @headers:List<&2, 0x1bc4d92e7c1f4dd1a49d87ad449b730b/src/http.Header> -> @body:0x1bc4d92e7c1f4dd1a49d87ad449b730b/src/body.Body -> IO(Response)

POST

def client.put source · line 153 · raw

@url:String -> @headers:List<&2, 0x1bc4d92e7c1f4dd1a49d87ad449b730b/src/http.Header> -> @body:0x1bc4d92e7c1f4dd1a49d87ad449b730b/src/body.Body -> IO(Response)

PUT

def client.delete source · line 158 · raw

@url:String -> @headers:List<&2, 0x1bc4d92e7c1f4dd1a49d87ad449b730b/src/http.Header> -> @body:0x1bc4d92e7c1f4dd1a49d87ad449b730b/src/body.Body -> IO(Response)

DELETE

def client.options source · line 163 · raw

@url:String -> @headers:List<&2, 0x1bc4d92e7c1f4dd1a49d87ad449b730b/src/http.Header> -> IO(Response)

OPTIONS

def client.bearer source · line 167 · raw

@token:String -> 0x1bc4d92e7c1f4dd1a49d87ad449b730b/src/http.Header

Authorization: Bearer … (auth.bend)

def client.basic source · line 171 · raw

@user:String -> @password:String -> 0x1bc4d92e7c1f4dd1a49d87ad449b730b/src/http.Header

Authorization: Basic … (auth.bend; RFC 7617, RFC 4648 Base64)