~/bend-docscommunity

src/wirespec.bend checks

raw source on the hub · import emerging-ezhttp@0.14.0.0/src/wirespec.bend as Wirespec

ezhttp/src/wirespec: the text the wire effect reads, and what its answer means, pure. Kept apart from wire.bend (the effect) so the proof gate can import it. What the client sends for a URL (wire.exchange) and when it has heard a whole answer (wire.read.next) are decided here; wire.bend and client.bend act on them.

Spec: scheme, host, port each on their own line; everything after the third newline is the request verbatim. The scheme line may carry a timeout after a space: 32 binary digits, least significant first, in milliseconds. A scheme line with no timeout means 60000 ms. SPEC.md HTTP-CLI lists what is guaranteed.

4 imports
import Base
import ./http.bend as Http
import ./url.bend as Url
import ./body.bend as Body

Types

type Exchange source · line 139 · raw

Data

what a request to a URL becomes: nothing when the URL did not parse, else the scheme (secure or not), host, port, method and request text the effect is given; the answer is read by that method (wire.read.next)

type Opened source · line 241 · raw

Data

what an open answered: a connection to read from, or the answer itself

type Read source · line 266 · raw

Data

after a read: read again with what has arrived, or answer

Definitions

def wire.scheme source · line 18 · raw

@secure:Bool -> String

the word the effect reads for a scheme that wants TLS

def wire.spec source · line 26 · raw

@secure:Bool -> @host:String -> @port:U32 -> @req:String -> String

the spec the effect reads

def wire.ms.dflt source · line 32 · raw

U32

the timeout a spec with none carries: 60 s, in milliseconds

def wire.bit source · line 36 · raw

@b:Bool -> Char

one bit as a binary digit

def wire.bits source · line 44 · raw

@n:Nat -> @w:Word(n) -> String

a word as binary digits, least significant first

def wire.bits.read source · line 54 · raw

@n:Nat -> @s:String -> Word(n)

binary digits, least significant first, as a word; a missing digit is 0

def wire.ms.text source · line 66 · raw

@ms:U32 -> String

a timeout as the scheme line carries it

def wire.head source · line 72 · raw

@secure:Bool -> @ms:U32 -> String

the first line of a timed spec: the scheme, a space, the timeout

def wire.rest source · line 76 · raw

@host:String -> @port:U32 -> @req:String -> String

the lines after the first: host, port, then the request verbatim

def wire.spec.timed source · line 80 · raw

@secure:Bool -> @ms:U32 -> @host:String -> @port:U32 -> @req:String -> String

the spec the effect reads, with a timeout in milliseconds

def wire.ms.words source · line 85 · raw

@ws:List<&2, String> -> U32

the timeout after the scheme word, or the default when there is none

def wire.line source · line 95 · raw

@ls:List<&2, String> -> String

the first line of a spec

def wire.ms source · line 103 · raw

@spec:String -> U32

the timeout the effect reads from a spec, in milliseconds

def wire.late source · line 110 · raw

U32

the wire status for an exchange that ran out of time (curl's CURLE_OPERATION_TIMEDOUT)

def wire.why.of source · line 115 · raw

@why:String -> @late:Bool -> String

what a failed exchange is reported as: a timeout is marked, any other failure's reason is kept as it is

def wire.why source · line 123 · raw

@code:Maybe<&2, U32> -> @why:String -> String

a failed exchange's status and reason as the reason the client reports

def wire.timed_out source · line 131 · raw

@why:String -> Bool

whether a reported reason is a timeout

def wire.exchange.at source · line 144 · raw

@+method:String -> @+secure:Bool -> @+host:String -> @+port:U32 -> @path:String -> @headers:List<&2, 0xa4d47e5f0f6044ac1a983d1b051fa47a/src/http.Header> -> @body:String -> Exchange

the exchange once it is known whether the scheme wants TLS

def wire.exchange.method source · line 151 · raw

@ex:Exchange -> Maybe<&2, String>

the method an exchange is sent and read by, none when nothing is sent

def wire.exchange source · line 159 · raw

@method:String -> @l:0xa4d47e5f0f6044ac1a983d1b051fa47a/src/url.Loc -> @headers:List<&2, 0xa4d47e5f0f6044ac1a983d1b051fa47a/src/http.Header> -> @body:String -> Exchange

a request with this method, headers and body to a URL that came apart

def wire.exchange.octets source · line 170 · raw

@+method:String -> @l:0xa4d47e5f0f6044ac1a983d1b051fa47a/src/url.Loc -> @headers:List<&2, 0xa4d47e5f0f6044ac1a983d1b051fa47a/src/http.Header> -> @n:Nat -> Exchange

a request with n octets of body to a URL that came apart: the request text ends at the blank line, and the octets go after it as the tail (wire.tail)

def wire.exchange.body source · line 182 · raw

@method:String -> @l:0xa4d47e5f0f6044ac1a983d1b051fa47a/src/url.Loc -> @headers:List<&2, 0xa4d47e5f0f6044ac1a983d1b051fa47a/src/http.Header> -> @b:0xa4d47e5f0f6044ac1a983d1b051fa47a/src/body.Body -> Exchange

a request with this body to a URL that came apart: text inside the request text as UTF-8, octets after it (SPEC.md HTTP-CLI-10)

def wire.tail source · line 193 · raw

@b:0xa4d47e5f0f6044ac1a983d1b051fa47a/src/body.Body -> List<&2, U32>

the octets sent after the request text: an octet body's, else none

def wire.code.of source · line 205 · raw

@c:0xa4d47e5f0f6044ac1a983d1b051fa47a/src/http.Cut -> @raw:String -> Maybe<&2, U32>

an answer's status: the number on its first line, if it is one

def wire.code source · line 213 · raw

@+raw:String -> Maybe<&2, U32>

an answer's status line as a number

def wire.text.of source · line 217 · raw

@c:0xa4d47e5f0f6044ac1a983d1b051fa47a/src/http.Cut -> String

the text after an answer's first newline

def wire.text source · line 225 · raw

@raw:String -> String

the text after an answer's first newline

def wire.ok.of source · line 229 · raw

@m:Maybe<&2, U32> -> Bool

whether a status is success (0)

def wire.ok source · line 237 · raw

@raw:String -> Bool

whether an answer has status 0

def wire.opened.conn source · line 246 · raw

@m:Maybe<&2, U32> -> Opened

a connection number that read, or a malformed answer when it did not

def wire.opened.of source · line 254 · raw

@+got:String -> @ok:Bool -> Opened

an open's answer once it is known whether it succeeded

def wire.opened source · line 262 · raw

@+got:String -> Opened

what an open's answer means

def wire.read.whole source · line 271 · raw

@all:String -> @done:Bool -> Read

everything received, once it is known whether it is a whole response

def wire.read.got source · line 279 · raw

@+method:String -> @acc:String -> @text:String -> @closed:Bool -> Read

a read that brought text, or found the connection closed

def wire.read.of source · line 289 · raw

@+method:String -> @acc:String -> @+got:String -> @ok:Bool -> Read

a read's answer once it is known whether it succeeded

def wire.read.next source · line 299 · raw

@+method:String -> @acc:String -> @+got:String -> Read

what to do after a read answered got, with acc received before it, for a request with this method (SPEC.md HTTP-CLI-6)

def wire.spent source · line 303 · raw

String

the answer when the reads run out before the response ends

def wire.heard.of source · line 309 · raw

@+method:String -> @+raw:String -> @ok:Bool -> 0xa4d47e5f0f6044ac1a983d1b051fa47a/src/http.Reply

the response an exchange's answer holds, read by the request's method (SPEC.md HTTP-CLI-9); a failed exchange is torn with the reason it is reported with (wire.why)

def wire.heard source · line 317 · raw

@+method:String -> @+raw:String -> 0xa4d47e5f0f6044ac1a983d1b051fa47a/src/http.Reply

the response an exchange's answer holds