~/bend-docscommunity

src/wirespec.bend checks

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

ezhttp/src/wirespec: what the client sends, when it has heard a whole answer, and what a failed socket call is reported as, pure. Kept apart from wire.bend (bend-kit-wire's effects) so the proof gate can import it. wire.bend and client.bend act on what is decided here.

A failed exchange's answer is a non-zero status on its first line, then the reason (wire.fail); a successful one is the response's octets, which wire.bend keeps packed and packed.bend reads. What is guaranteed is under laws/, such as laws/RequestLineAndHost.bend.

6 imports
import Base
import ./http.bend as Http
import ./url.bend as Url
import ./body.bend as Body
import ./pct.bend as Pct
import ./qs.bend as Qs

Types

type Exchange source · line 79 · 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 Read source · line 196 · raw

Data

after a read: read again from where the response now stands, or it has all been received

type Phase source · line 295 · raw

Data

where in an exchange a call failed

Definitions

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

U32

the deadline of an exchange with no timeout: 60 s, in milliseconds

def wire.ms.pick source · line 24 · raw

@ms:U32 -> @zero:Bool -> U32

a timeout once it is known whether it is 0

def wire.ms.at source · line 33 · raw

@+ms:U32 -> U32

a timeout as a deadline bend-kit-wire reads: 0 would be none there, so it is 1 ms

def wire.ms.of source · line 39 · raw

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

the deadline every socket call of an exchange gets: the timeout it was made with, or the default (laws/DeadlineIsTimeout.bend, laws/TimeoutZeroIsOneMs.bend)

def wire.late source · line 50 · raw

U32

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

def wire.why.of source · line 55 · 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 63 · 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 71 · raw

@why:String -> Bool

whether a reported reason is a timeout

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

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

the exchange once it is known whether the scheme wants TLS

def wire.exchange.method source · line 91 · 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 99 · raw

@method:String -> @l:0x7367809738fddd234b8d2bed772ad2cf/src/url.Loc -> @headers:List<&2, 0x7367809738fddd234b8d2bed772ad2cf/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 110 · raw

@+method:String -> @l:0x7367809738fddd234b8d2bed772ad2cf/src/url.Loc -> @headers:List<&2, 0x7367809738fddd234b8d2bed772ad2cf/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

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

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

a request with a body of this shape to a URL that came apart: text inside the request text as UTF-8, octets after it (laws/OctetBodiesSentUnchanged.bend)

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

@c:0x7367809738fddd234b8d2bed772ad2cf/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 142 · raw

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

an answer's status line as a number

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

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

the text after an answer's first newline

def wire.text source · line 154 · raw

@raw:String -> String

the text after an answer's first newline

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

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

whether a status is success (0)

def wire.ok source · line 166 · raw

@raw:String -> Bool

whether an answer has status 0

def wire.joined source · line 170 · raw

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

the text a list of pieces, newest first, stands for

def wire.join.go source · line 178 · raw

@ps:List<&2, String> -> @acc:String -> String

the pieces put together onto what follows them, each copied once

def wire.join source · line 186 · 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 191 · raw

@+method:String -> 0x7367809738fddd234b8d2bed772ad2cf/src/http.Hear

where a response to a request with this method stands before anything has been received

def wire.read.done source · line 201 · raw

@+h:0x7367809738fddd234b8d2bed772ad2cf/src/http.Hear -> @done:Bool -> Read

where the response stands after a read, judged

def wire.read.with source · line 209 · raw

@+h:0x7367809738fddd234b8d2bed772ad2cf/src/http.Hear -> Read

where the response stands after a read, judged

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

@h:0x7367809738fddd234b8d2bed772ad2cf/src/http.Hear -> @+text:String -> @closed:Bool -> Read

a read that brought text, or found the connection closed

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

@h:0x7367809738fddd234b8d2bed772ad2cf/src/http.Hear -> @+text:String -> Read

what to do after a read brought this text, judged from where the response stood (laws/ReadsJudgedByCount.bend)

def wire.read.counted source · line 226 · raw

@+h:0x7367809738fddd234b8d2bed772ad2cf/src/http.Hear -> @+m:Nat -> @counts:Bool -> Maybe<&2, Read>

a read of m octets judged by its count, when that is enough to judge it

def wire.read.count.at source · line 234 · raw

@+h:0x7367809738fddd234b8d2bed772ad2cf/src/http.Hear -> @+m:Nat -> @closed:Bool -> Maybe<&2, Read>

a read of m octets: none is the close

def wire.read.count source · line 245 · raw

@+h:0x7367809738fddd234b8d2bed772ad2cf/src/http.Hear -> @+m:Nat -> Maybe<&2, Read>

what to do after a read of m octets, when their count alone decides it; none when their text is needed (wire.read.next) (laws/ReadsJudgedByCount.bend)

def wire.spent source · line 249 · raw

String

the answer when the reads run out before the response ends

def wire.failed source · line 253 · raw

@+raw:String -> String

the reason a failed exchange's answer is reported with (wire.why)

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

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

the response an exchange's answer holds, read by the request's method (laws/InterimResponsesSkipped.bend); a failed exchange is torn with the reason it is reported with (wire.why)

def wire.phrase source · line 269 · raw

@raw:String -> String

the reason phrase of the response an exchange's answer holds (laws/ReasonPhraseFromFinalHead.bend); a failed exchange's is read from its reason and not used

def wire.heard source · line 273 · raw

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

the response an exchange's answer holds

def wire.payload.text source · line 279 · raw

@s:String -> @rest:String -> String

a request text's UTF-8 octets, one character each, onto the octets after it

def wire.payload source · line 288 · raw

@req:String -> String

the octets of a request text, one character each: its UTF-8 (the body's octets go after them)

def wire.etimedout source · line 303 · raw

U32

the error number a call that ran out of time fails with (Linux ETIMEDOUT)

def wire.errnos source · line 307 · raw

List<&2, 0x7367809738fddd234b8d2bed772ad2cf/src/http.Phrase>

the Linux errno symbols this table names

def wire.errno.or source · line 324 · raw

@name:String -> String

a name from the table, or errno when it has none

def wire.errno.name source · line 332 · raw

@+n:U32 -> String

an error number's name (laws/ErrnoNamesAreLinux.bend)

def wire.cause source · line 336 · raw

@+n:U32 -> String

an error number as a reason names it: <name> (<n>)

def wire.fail.resolve source · line 341 · raw

@host:String -> @+n:U32 -> @none:Bool -> String

a resolve's failure: bend-kit-dns reports a name with no address as ENOENT, whose name would read as a missing file, so only the host is named

def wire.fail.late source · line 349 · raw

@p:Phase -> @host:String -> @+port:U32 -> @+ms:U32 -> @+n:U32 -> String

a call that ran out of time, by its phase

def wire.fail.other source · line 367 · raw

@p:Phase -> @host:String -> @+port:U32 -> @+n:U32 -> @why:String -> String

a call that failed for another reason, by its phase

def wire.fail.of source · line 384 · raw

@p:Phase -> @host:String -> @+port:U32 -> @+ms:U32 -> @+n:U32 -> @why:String -> @late:Bool -> String

a failure once it is known whether it ran out of time

def wire.fail source · line 408 · raw

@p:Phase -> @host:String -> @+port:U32 -> @+ms:U32 -> @+n:U32 -> @why:String -> String

the exchange's answer when a call in this phase failed with error number n and reason why, with deadline ms (laws/FailuresReportedByPhase.bend).

Trusted, not proved: bend-kit-wire and bend-kit-dns report a failed call as the platform's errno number and its strerror text, except that tls.connect reports a failed handshake as EPROTO with OpenSSL's verify reason (or TLS handshake failed), and lookup.all reports a name that does not resolve as ENOENT, a temporary failure as EAGAIN, running out of memory as ENOMEM and any other getaddrinfo failure as EIO; a call whose deadline passes fails with ETIMEDOUT and no other call does. The names laws/ErrnoNamesAreLinux.bend gives are Linux's numbering. It is foreign C and JS reading errno, getaddrinfo and OpenSSL, which no law reaches. What each number is named and what a failed exchange is reported as are proved (laws/FailuresReportedByPhase.bend, laws/ErrnoNamesAreLinux.bend), and that the reason reaches Client.Err unchanged (laws/TimeoutsReadAsTimedOut.bend, laws/InterimResponsesSkipped.bend).