src/wire.bend relies on unsafe/foreign
raw source on the hub · import ezhttp@0.25.0.0/src/wire.bend as Wire
ezhttp/src/wire: one request out and one response back, over bend-kit-wire's sockets. Its effects park on the runtime's event loop, so exchanges run side by side under IO.fork. bend-kit-dns resolves the host; TLS is bend-kit-wire's (OpenSSL 3 loaded at run time, BEND_LIBSSL to point at it).
An exchange's answer is every octet of the response, packed (Received), or a failure: a non-zero status on its first line, then the reason (wirespec.bend wire.fail). Every decision is wirespec.bend's: the deadline (wire.ms.of), the octets sent (wire.payload), what a failed call is reported as (wire.fail) and when the response is whole (wire.read.count, else wire.read.next on a copy of the receive as text), so a server that keeps the connection open after a complete response is not waited on (laws/DeadlineIsTimeout.bend, laws/ReadsJudgedByCount.bend, laws/OctetBodiesSentUnchanged.bend, laws/FailuresReportedByPhase.bend; the sequencing is trusted in src/client.bend).
Trusted, not proved: bend-kit-wire@0.4.6.1 (Wire.connect,
Wire.tls.connect, Wire.send.words.deadline, Wire.tls.send.words,
Wire.recv.words, Wire.tls.recv.words, Wire.tls.close),
bend-kit-dns@0.6.0.2 (Dns.resolve.literal.all, Dns.lookup.all) and
bend-kit-bytes@0.3.2.0 (Bytes.from_string, Bytes.to_string,
Bytes.length, Bytes.append, Bytes.concat, Bytes.find,
Bytes.find.from, Bytes.slice, Bytes.new) do what their comments say:
connect connects to a numeric address within its deadline;
tls.connect checks the server's certificate chain and host name within
its deadline; send.words.deadline sends all len octets within its
deadline, and tls.send.words all of them with no deadline; recv.words
and tls.recv.words answer at least one octet that arrived within the
deadline, as many as are waiting up to max, and 0 octets once the server
has closed (over TLS, once it has sent close_notify); a deadline of 0 is
none; from_string packs one octet per character (its low 8 bits) and
to_string gives one character per octet; length answers the number of
octets, append and concat put octets together in order, find
answers where a run of octets first occurs (none when it does not) and
find.from where it first occurs at or after an offset, slice gives the
buffer back with a copy of up to n octets from an offset, and new(0)
is no octets; lookup.all asks the OS resolver and answers every address.
Name resolution is not bounded by the deadline. They are another
project's code (github.com/paymog/bend-kit, Apache-2.0), pinned by hash in
ez.toml and upgraded deliberately: foreign C and JS (effs/wire.c,
wire.js, effs/dns.c, dns.js) over sockets, getaddrinfo and OpenSSL,
and Bend over packed Array<U32> words that no law here reaches.
bend-kit-wire ships no LAWS file, so nothing proves its comments. What the
deadline is, what is sent, what a failure is reported as and when the
answer is complete are proved (laws/DeadlineIsTimeout.bend,
laws/OctetBodiesSentUnchanged.bend, laws/FailuresReportedByPhase.bend,
laws/ReadsJudgedByCount.bend); bend-kit decides none of them.
6 imports
import Base import bend-kit-wire@0.4.6.1/wire.bend as W import bend-kit-bytes@0.3.2.0/bytes.bend as Bytes import bend-kit-dns@0.6.0.2/dns.bend as Dns import ./wirespec.bend as Spec import ./http.bend as Http
Types
type Answer source · line 127 · raw
Type
an exchange's answer: the failure it was reported with (a status other than 0 on its first line, then the reason, wirespec.bend wire.fail), or every octet of the response, packed
Failed@answer:String -> Answer
Received@octets:0x185ae03c75e3e75be1171471f68b43cb/bytes.Bytes -> Answer
Definitions
def wire.max source · line 57 · raw
U32
the most octets one receive asks for
def wire.reads source · line 61 · raw
Nat
the most receives one exchange makes
def wire.close source · line 67 · raw
@secure:Bool -> @s:Socket -> IO(Unit)
close a socket, ending its TLS session when it has one
def wire.recv source · line 75 · raw
@secure:Bool -> @s:Socket -> @ms:U32 -> IO(Pair(Socket, Result<&1, &1, Pair(U32, String), Pair(U32, Array<U32>)>))
the next octets a socket has received, packed four to a word
def wire.sent source · line 87 · raw
@r:Pair(Socket, Pair(U32, Result<&1, &1, Pair(U32, String), Unit>)) -> IO(Pair(Socket, Result<&1, &1, Pair(U32, String), Unit>))
a send.words.deadline answer without its count of octets accepted
def wire.send source · line 94 · raw
@secure:Bool -> @s:Socket -> @+len:U32 -> @buf:Array<U32> -> @ms:U32 -> IO(Pair(Socket, Result<&1, &1, Pair(U32, String), Unit>))
send octets, the plain send bounded by the deadline
def wire.shake source · line 110 · raw
@secure:Bool -> @s:Socket -> @host:String -> @ms:U32 -> IO(Pair(Socket, Result<&1, &1, Pair(U32, String), Unit>))
the TLS handshake with the host, when the exchange is secure
def wire.failed source · line 132 · raw
@+secure:Bool -> @s:Socket -> @answer:String -> IO(Answer)
a failed call's answer, the socket closed first
def wire.loop.on source · line 137 · raw
@+secure:Bool -> @s:Socket -> @r:0x0b59049ea5717d6f2fd30293c7271ede/src/wirespec.Read -> @acc:0x185ae03c75e3e75be1171471f68b43cb/bytes.Bytes -> @more:(@_:Socket -> @_:0x0b59049ea5717d6f2fd30293c7271ede/src/http.Hear -> @_:0x185ae03c75e3e75be1171471f68b43cb/bytes.Bytes -> IO(Answer)) -> IO(Answer)
a judged read: read again, or close and answer what was received
def wire.loop.copied source · line 153 · raw
@+secure:Bool -> @s:Socket -> @h:0x0b59049ea5717d6f2fd30293c7271ede/src/http.Hear -> @r:Pair(0x185ae03c75e3e75be1171471f68b43cb/bytes.Bytes, 0x185ae03c75e3e75be1171471f68b43cb/bytes.Bytes) -> @acc:0x185ae03c75e3e75be1171471f68b43cb/bytes.Bytes -> @more:(@_:Socket -> @_:0x0b59049ea5717d6f2fd30293c7271ede/src/http.Hear -> @_:0x185ae03c75e3e75be1171471f68b43cb/bytes.Bytes -> IO(Answer)) -> IO(Answer)
a receive judged by a copy of it as text, dropped after the judging; the octets themselves are appended packed
def wire.loop.text source · line 166 · raw
@+secure:Bool -> @s:Socket -> @h:0x0b59049ea5717d6f2fd30293c7271ede/src/http.Hear -> @piece:0x185ae03c75e3e75be1171471f68b43cb/bytes.Bytes -> @acc:0x185ae03c75e3e75be1171471f68b43cb/bytes.Bytes -> @more:(@_:Socket -> @_:0x0b59049ea5717d6f2fd30293c7271ede/src/http.Hear -> @_:0x185ae03c75e3e75be1171471f68b43cb/bytes.Bytes -> IO(Answer)) -> IO(Answer)
a read judged by its text, when its count alone does not decide it
def wire.loop.judge source · line 178 · raw
@+secure:Bool -> @s:Socket -> @h:0x0b59049ea5717d6f2fd30293c7271ede/src/http.Hear -> @piece:0x185ae03c75e3e75be1171471f68b43cb/bytes.Bytes -> @acc:0x185ae03c75e3e75be1171471f68b43cb/bytes.Bytes -> @counted:Maybe<&2, 0x0b59049ea5717d6f2fd30293c7271ede/src/wirespec.Read> -> @more:(@_:Socket -> @_:0x0b59049ea5717d6f2fd30293c7271ede/src/http.Hear -> @_:0x185ae03c75e3e75be1171471f68b43cb/bytes.Bytes -> IO(Answer)) -> IO(Answer)
a read judged by its count when that decides it (laws/ReadsJudgedByCount.bend)
def wire.loop.un source · line 194 · raw
@+secure:Bool -> @+host:String -> @+port:U32 -> @+ms:U32 -> @+h:0x0b59049ea5717d6f2fd30293c7271ede/src/http.Hear -> @acc:0x185ae03c75e3e75be1171471f68b43cb/bytes.Bytes -> @r:Pair(Socket, Result<&1, &1, Pair(U32, String), Pair(U32, Array<U32>)>) -> @more:(@_:Socket -> @_:0x0b59049ea5717d6f2fd30293c7271ede/src/http.Hear -> @_:0x185ae03c75e3e75be1171471f68b43cb/bytes.Bytes -> IO(Answer)) -> IO(Answer)
a receive's outcome: a failure is the answer
def wire.loop source · line 215 · raw
@fuel:Nat -> @+secure:Bool -> @s:Socket -> @+host:String -> @+port:U32 -> @+ms:U32 -> @h:0x0b59049ea5717d6f2fd30293c7271ede/src/http.Hear -> @acc:0x185ae03c75e3e75be1171471f68b43cb/bytes.Bytes -> IO(Answer)
receive until wirespec.bend says the answer is whole, the octets appended to what came before
def wire.after.send source · line 237 · raw
@+secure:Bool -> @+host:String -> @+port:U32 -> @+ms:U32 -> @+method:String -> @r:Pair(Socket, Result<&1, &1, Pair(U32, String), Unit>) -> IO(Answer)
after the send: read the answer, or the send's failure
def wire.put source · line 255 · raw
@+secure:Bool -> @s:Socket -> @+host:String -> @+port:U32 -> @+ms:U32 -> @+method:String -> @payload:0x185ae03c75e3e75be1171471f68b43cb/bytes.Bytes -> IO(Answer)
send the octets an exchange carries, then read its answer
def wire.after.shake source · line 271 · raw
@+secure:Bool -> @+host:String -> @+port:U32 -> @+ms:U32 -> @+method:String -> @payload:0x185ae03c75e3e75be1171471f68b43cb/bytes.Bytes -> @r:Pair(Socket, Result<&1, &1, Pair(U32, String), Unit>) -> IO(Answer)
after the handshake: send, or the handshake's failure (the socket closed plainly, as no TLS session was made)
def wire.after.connect source · line 290 · raw
@+secure:Bool -> @+host:String -> @+port:U32 -> @+ms:U32 -> @+method:String -> @payload:0x185ae03c75e3e75be1171471f68b43cb/bytes.Bytes -> @r:Result<&1, &1, Pair(U32, String), Socket> -> IO(Answer)
after the connect: the handshake, or the connect's failure
def wire.dial.next source · line 309 · raw
@r:Result<&1, &1, Pair(U32, String), Socket> -> @more:(@_:Unit -> IO(Result<&1, &1, Pair(U32, String), Socket>)) -> IO(Result<&1, &1, Pair(U32, String), Socket>)
a connect that failed tries the next address; one that worked is kept
def wire.dial source · line 321 · raw
@rest:List<&2, String> -> @+first:String -> @+port:U32 -> @+ms:U32 -> IO(Result<&1, &1, Pair(U32, String), Socket>)
connect to each address in turn until one connects; the last one's failure when none does
def wire.after.resolve source · line 338 · raw
@+secure:Bool -> @+host:String -> @+port:U32 -> @+ms:U32 -> @+method:String -> @payload:0x185ae03c75e3e75be1171471f68b43cb/bytes.Bytes -> @r:Result<&1, &1, Pair(U32, String), List<&2, String>> -> IO(Answer)
after the resolve: connect, or the resolve's failure (no address at all is ENOENT, as bend-kit-dns reports a name with none)
def wire.looked source · line 360 · raw
@r:Result<&1, &1, Pair(U32, String), String> -> IO(Result<&1, &1, Pair(U32, String), List<&2, String>>)
the OS resolver's addresses, NUL-separated, as a list
def wire.resolve source · line 372 · raw
@+host:String -> @literal:List<&2, String> -> IO(Result<&1, &1, Pair(U32, String), List<&2, String>>)
a host's addresses: a numeric address or localhost as it is, else the OS resolver's answer
def wire.run.with source · line 385 · raw
@+secure:Bool -> @+ms:U32 -> @+host:String -> @+port:U32 -> @+method:String -> @payload:0x185ae03c75e3e75be1171471f68b43cb/bytes.Bytes -> IO(Answer)
the exchange once its octets are packed
def wire.run source · line 400 · raw
@+secure:Bool -> @+ms:U32 -> @+host:String -> @+port:U32 -> @+method:String -> @req:String -> @tail:0x185ae03c75e3e75be1171471f68b43cb/bytes.Bytes -> IO(Answer)
a request with this method, sent to a host as wirespec.bend says, with its tail of octets after it, every call bounded by the deadline; its whole answer
def wire.talk source · line 414 · raw
@secure:Bool -> @host:String -> @port:U32 -> @method:String -> @req:String -> @tail:0x185ae03c75e3e75be1171471f68b43cb/bytes.Bytes -> IO(Answer)
a request sent to a host, its tail of octets after it, and its whole answer read back, with the default deadline
def wire.talk.timed source · line 425 · raw
@secure:Bool -> @ms:U32 -> @host:String -> @port:U32 -> @method:String -> @req:String -> @tail:0x185ae03c75e3e75be1171471f68b43cb/bytes.Bytes -> IO(Answer)
the same exchange, bounded by a timeout in milliseconds