~/bend-docscommunity

src/wire.bend relies on unsafe/foreign

raw source on the hub · import emerging-ezhttp@0.17.0.0/src/wire.bend as Wire

ezhttp/src/wire: one request out and one response back. TLS and DNS stay in the effect (OpenSSL via dlopen); this module does not re-specify TLS.

Spec: scheme, host, port each on their own line; everything after the third newline is the request verbatim, and a list of octets (the body's tail, wirespec.bend wire.tail) is sent after it byte for byte; the scheme line may carry a timeout (wirespec.bend). Answer: status on the first line, then text ("0" and the raw response, or a non-zero code and the reason).

The effect opens a connection and sends the request, then answers one read at a time; when the response is whole is wirespec.bend's decision (wire.read.next), so a server that keeps the connection open after a complete response is not waited on (SPEC.md HTTP-CLI-5, HTTP-CLI-6).

2 imports
import Base
import ./wirespec.bend as Spec

Definitions

def wire.spec source · line 34 · raw

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

the spec the effect reads (wirespec.bend)

def wire.reads source · line 38 · raw

Nat

the most reads one exchange makes

def wire.loop.on source · line 42 · raw

@r:0x2c3360c0ff9d38b16f7c5d3da25532d7/src/wirespec.Read -> @more:(@_:0x2c3360c0ff9d38b16f7c5d3da25532d7/src/wirespec.Got -> IO(String)) -> IO(String)

a read's outcome: read again, or the answer

def wire.loop source · line 50 · raw

@fuel:Nat -> @+conn:U32 -> @acc:0x2c3360c0ff9d38b16f7c5d3da25532d7/src/wirespec.Got -> IO(String)

read until wirespec.bend says the answer is whole

def wire.hear source · line 61 · raw

@+conn:U32 -> @method:String -> IO(String)

read the answer on an open connection, then close it

def wire.after source · line 69 · raw

@o:0x2c3360c0ff9d38b16f7c5d3da25532d7/src/wirespec.Opened -> @method:String -> IO(String)

an open's outcome: read from the connection, or the answer

def wire.run source · line 78 · raw

@method:String -> @spec:String -> @tail:List<&2, U32> -> IO(String)

a request with this method, sent as a spec says with its tail of octets after it, and its whole answer

def wire.talk source · line 86 · raw

@secure:Bool -> @host:String -> @port:U32 -> @method:String -> @req:String -> @tail:List<&2, U32> -> IO(String)

a request sent to a host, its tail of octets after it, and its whole answer read back

def wire.talk.timed source · line 91 · raw

@secure:Bool -> @ms:U32 -> @host:String -> @port:U32 -> @method:String -> @req:String -> @tail:List<&2, U32> -> IO(String)

the same exchange, bounded by a timeout in milliseconds

Effects (foreign code)

effect ezwire.open source · line 19 · raw

@spec:String -> @tail:List<&2, U32> -> IO(String)

connect, send the request a spec carries and then the tail's octets as bytes, and answer a connection number

foreign: src/effs/wire.c, src/effs/wire.js

effect ezwire.read source · line 24 · raw

@conn:U32 -> IO(String)

the next octets a connection has received, "" once the server has closed

foreign: src/effs/wire.c, src/effs/wire.js

effect ezwire.close source · line 29 · raw

@conn:U32 -> IO(Unit)

close a connection

foreign: src/effs/wire.c, src/effs/wire.js