src/wirespec.bend checks
raw source on the hub · import emerging-ezhttp@0.17.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)
NoUrl@why:String -> Exchange
Exchange@secure:Bool -> @host:String -> @port:U32 -> @method:String -> @req:String -> Exchange
type Opened source · line 241 · raw
Data
what an open answered: a connection to read from, or the answer itself
Refused@answer:String -> Opened
Open@conn:U32 -> Opened
type Got source · line 267 · raw
Data
what has been received so far: its pieces, the newest first, and where the response stands (Http.hear)
Got@pieces:List<&2, String> -> @hear:0x2c3360c0ff9d38b16f7c5d3da25532d7/src/http.Hear -> Got
type Read source · line 295 · raw
Data
after a read: read again with what has arrived, or answer
Again@acc:Got -> Read
Heard@answer:String -> Read
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, 0x2c3360c0ff9d38b16f7c5d3da25532d7/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:0x2c3360c0ff9d38b16f7c5d3da25532d7/src/url.Loc -> @headers:List<&2, 0x2c3360c0ff9d38b16f7c5d3da25532d7/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:0x2c3360c0ff9d38b16f7c5d3da25532d7/src/url.Loc -> @headers:List<&2, 0x2c3360c0ff9d38b16f7c5d3da25532d7/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:0x2c3360c0ff9d38b16f7c5d3da25532d7/src/url.Loc -> @headers:List<&2, 0x2c3360c0ff9d38b16f7c5d3da25532d7/src/http.Header> -> @b:0x2c3360c0ff9d38b16f7c5d3da25532d7/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:0x2c3360c0ff9d38b16f7c5d3da25532d7/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:0x2c3360c0ff9d38b16f7c5d3da25532d7/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:0x2c3360c0ff9d38b16f7c5d3da25532d7/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.joined source · line 271 · raw
@ps:List<&2, String> -> String
the text a list of pieces, newest first, stands for
def wire.join.go source · line 279 · raw
@ps:List<&2, String> -> @acc:String -> String
the pieces put together onto what follows them, each copied once
def wire.join source · line 287 · raw
@ps:List<&2, String> -> String
the text a list of pieces, newest first, stands for, built in one pass
def wire.got source · line 291 · raw
@+method:String -> @+ps:List<&2, String> -> Got
what has been received as these pieces, for a request with this method
def wire.read.whole source · line 300 · raw
@+ps:List<&2, String> -> @h:0x2c3360c0ff9d38b16f7c5d3da25532d7/src/http.Hear -> @done:Bool -> Read
everything received, once it is known whether it is a whole response
def wire.read.add source · line 308 · raw
@text:String -> @ps:List<&2, String> -> @+h:0x2c3360c0ff9d38b16f7c5d3da25532d7/src/http.Hear -> Read
a read that brought text, judged with where the response now stands
def wire.read.got source · line 312 · raw
@st:Got -> @+text:String -> @closed:Bool -> Read
a read that brought text, or found the connection closed
def wire.read.of source · line 320 · raw
@st:Got -> @+got:String -> @ok:Bool -> Read
a read's answer once it is known whether it succeeded
def wire.read.next source · line 330 · raw
@st:Got -> @+got:String -> Read
what to do after a read answered got, with what was received before it
(SPEC.md HTTP-CLI-6)
def wire.spent source · line 334 · raw
String
the answer when the reads run out before the response ends
def wire.heard.of source · line 340 · raw
@+method:String -> @+raw:String -> @ok:Bool -> 0x2c3360c0ff9d38b16f7c5d3da25532d7/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.phrase source · line 349 · raw
@raw:String -> String
the reason phrase of the response an exchange's answer holds (SPEC.md HTTP-CLI-11); a failed exchange's is read from its reason and not used
def wire.heard source · line 353 · raw
@+method:String -> @+raw:String -> 0x2c3360c0ff9d38b16f7c5d3da25532d7/src/http.Reply
the response an exchange's answer holds