src/wirespec.bend checks
raw source on the hub · import emerging-ezhttp@0.13.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.
3 imports
import Base import ./http.bend as Http import ./url.bend as Url
Types
type Exchange source · line 138 · 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)
NoUrl@why:String -> Exchange
Exchange@secure:Bool -> @host:String -> @port:U32 -> @method:String -> @req:String -> Exchange
type Opened source · line 206 · raw
Data
what an open answered: a connection to read from, or the answer itself
Refused@answer:String -> Opened
Open@conn:U32 -> Opened
type Read source · line 231 · raw
Data
after a read: read again with what has arrived, or answer
Again@acc:String -> Read
Heard@answer:String -> Read
Definitions
def wire.scheme source · line 17 · raw
@secure:Bool -> String
the word the effect reads for a scheme that wants TLS
def wire.spec source · line 25 · raw
@secure:Bool -> @host:String -> @port:U32 -> @req:String -> String
the spec the effect reads
def wire.ms.dflt source · line 31 · raw
U32
the timeout a spec with none carries: 60 s, in milliseconds
def wire.bit source · line 35 · raw
@b:Bool -> Char
one bit as a binary digit
def wire.bits source · line 43 · raw
@n:Nat -> @w:Word(n) -> String
a word as binary digits, least significant first
def wire.bits.read source · line 53 · 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 65 · raw
@ms:U32 -> String
a timeout as the scheme line carries it
def wire.head source · line 71 · raw
@secure:Bool -> @ms:U32 -> String
the first line of a timed spec: the scheme, a space, the timeout
def wire.rest source · line 75 · 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 79 · 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 84 · raw
@ws:List<&2, String> -> U32
the timeout after the scheme word, or the default when there is none
def wire.line source · line 94 · raw
@ls:List<&2, String> -> String
the first line of a spec
def wire.ms source · line 102 · raw
@spec:String -> U32
the timeout the effect reads from a spec, in milliseconds
def wire.late source · line 109 · raw
U32
the wire status for an exchange that ran out of time (curl's CURLE_OPERATION_TIMEDOUT)
def wire.why.of source · line 114 · 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 122 · 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 130 · raw
@why:String -> Bool
whether a reported reason is a timeout
def wire.exchange.at source · line 143 · raw
@+method:String -> @+secure:Bool -> @+host:String -> @+port:U32 -> @path:String -> @headers:List<&2, 0xd3f9c1f02240edb63fd4a109ceb8fa74/src/http.Header> -> @body:String -> Exchange
the exchange once it is known whether the scheme wants TLS
def wire.exchange.method source · line 150 · 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 158 · raw
@method:String -> @l:0xd3f9c1f02240edb63fd4a109ceb8fa74/src/url.Loc -> @headers:List<&2, 0xd3f9c1f02240edb63fd4a109ceb8fa74/src/http.Header> -> @body:String -> Exchange
a request with this method, headers and body to a URL that came apart
def wire.code.of source · line 170 · raw
@c:0xd3f9c1f02240edb63fd4a109ceb8fa74/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 178 · raw
@+raw:String -> Maybe<&2, U32>
an answer's status line as a number
def wire.text.of source · line 182 · raw
@c:0xd3f9c1f02240edb63fd4a109ceb8fa74/src/http.Cut -> String
the text after an answer's first newline
def wire.text source · line 190 · raw
@raw:String -> String
the text after an answer's first newline
def wire.ok.of source · line 194 · raw
@m:Maybe<&2, U32> -> Bool
whether a status is success (0)
def wire.ok source · line 202 · raw
@raw:String -> Bool
whether an answer has status 0
def wire.opened.conn source · line 211 · 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 219 · raw
@+got:String -> @ok:Bool -> Opened
an open's answer once it is known whether it succeeded
def wire.opened source · line 227 · raw
@+got:String -> Opened
what an open's answer means
def wire.read.whole source · line 236 · raw
@all:String -> @done:Bool -> Read
everything received, once it is known whether it is a whole response
def wire.read.got source · line 244 · 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 254 · 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 264 · 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 268 · raw
String
the answer when the reads run out before the response ends