io.bend relies on unsafe/foreign
raw source on the hub · import element-http@0.1.0.0/io.bend as Io
7 imports
import Base import ./sock.bend as Sock import element-tls13@0.1.0.0/client.bend as C import element-hostio@0.1.0.0/clock.bend as Wall import element-x509@0.1.0.0/cert.bend as X509 import element-x509@0.1.0.0/pem.bend as Pem import ./http.bend as Http
Types
type TS source · line 22 · raw
Type
Go carries the response's framing (Http.Fr) and how many plaintext records it has read, so each record's bytes are framed once.
Go@sock:Socket -> @cs:0xb50db566077215d442e9798060f35e33/client.Cs -> @fr:0x475c2a8333a479bccfdd668aaa51426c/http.Fr -> @seen:Nat -> TS
Finish@sock:Socket -> @out:List<&2, U32> -> TS
Framed@sock:Socket -> @cs:0xb50db566077215d442e9798060f35e33/client.Cs -> TS
Abort@sock:Socket -> @msg:String -> TS
type Ended source · line 121 · raw
Type
What an exchange leaves: its result, and the session when the response was whole by its framing and the server keeps the connection (the pool lends it again); otherwise the socket is closed here.
Ended@res:Result<&1, &1, Pair(U32, String), List<&2, U32>> -> @keep:Maybe<&1, Sess> -> Ended
type Sess source · line 124 · raw
Type
Sess@sock:Socket -> @cs:0xb50db566077215d442e9798060f35e33/client.Cs -> Sess
type Store source · line 249 · raw
Data
The trusted roots, parsed once. Parsing the system bundle (128 roots, 333 KB on macOS) took about 0.4 s of CPU, and it was done for every https connection: a page with 30 https subresources paid it 30 times. Unverified the caller's explicit opt-out Lazy verify, reading the bundle per connection: a run that may never open one (a local file) does not pay at start Loaded verify against roots parsed once (a URL fetch, the servers) Pooled another store's trust, through a pool of open sessions (pool_start: one client's connections, reused)
UnverifiedStore
LazyStore
Loaded@roots:List<&2, 0xd276682e9f8b76d0870e36f1d43799d6/cert.Cert> -> Store
Pooled@base:Store -> @inbox:Chan(PAsk) -> Store
type PAsk source · line 333 · raw
Type
PTake@key:String -> @reply:Chan(Maybe<&1, Sess>) -> PAsk
PPut@key:String -> @s:Sess -> PAsk
PGone@key:String -> PAsk
PEndPAsk
type Idle source · line 345 · raw
Type
Idle@key:String -> @s:Sess -> Idle
type Open source · line 348 · raw
Data
Open@key:String -> @n:U32 -> Open
type Waiter source · line 351 · raw
Type
Waiter@key:String -> @reply:Chan(Maybe<&1, Sess>) -> Waiter
type Eff source · line 354 · raw
Type
EReply@reply:Chan(Maybe<&1, Sess>) -> @m:Maybe<&1, Sess> -> Eff
EClose@s:Sess -> Eff
type PS source · line 359 · raw
Type
The pool's state, and what to do before the next ask.
PS@idle:List<&1, Idle> -> @open:List<&2, Open> -> @waits:List<&1, Waiter> -> @effs:List<&1, Eff> -> PS
PStop@idle:List<&1, Idle> -> @waits:List<&1, Waiter> -> PS
type TakeI source · line 384 · raw
Type
the first idle session for key, and the others
TakeI@m:Maybe<&1, Sess> -> @rest:List<&1, Idle> -> TakeI
type TakeW source · line 419 · raw
Type
TakeW@m:Maybe<&1, Chan(Maybe<&1, Sess>)> -> @rest:List<&1, Waiter> -> TakeW
type Counted source · line 479 · raw
Type
the idle sessions and how many (a list of sockets is read once)
Counted@n:Nat -> @xs:List<&1, Idle> -> Counted
Definitions
def over_cap source · line 28 · raw
@over:Bool -> @s:Socket -> @+cs:0xb50db566077215d442e9798060f35e33/client.Cs -> @fr:0x475c2a8333a479bccfdd668aaa51426c/http.Fr -> @+seen:Nat -> TS
def app_state source · line 37 · raw
@done:Bool -> @s:Socket -> @+cs:0xb50db566077215d442e9798060f35e33/client.Cs -> @+cap:U32 -> @fr:0x475c2a8333a479bccfdd668aaa51426c/http.Fr -> @+seen:Nat -> TS
Application data that is a whole HTTP response by its framing ends the exchange, though the server may keep the connection open (keep-alive).
def app_fed source · line 45 · raw
@s:Socket -> @+cs:0xb50db566077215d442e9798060f35e33/client.Cs -> @+cap:U32 -> @fr:0x475c2a8333a479bccfdd668aaa51426c/http.Fr -> @+seen:Nat -> TS
the records this feed added (out is newest first) go through the framing
def classify source · line 52 · raw
@p:0xb50db566077215d442e9798060f35e33/client.Phase -> @s:Socket -> @+cs:0xb50db566077215d442e9798060f35e33/client.Cs -> @+cap:U32 -> @fr:0x475c2a8333a479bccfdd668aaa51426c/http.Fr -> @+seen:Nat -> TS
def at_eof source · line 73 · raw
@p:0xb50db566077215d442e9798060f35e33/client.Phase -> @s:Socket -> @+cs:0xb50db566077215d442e9798060f35e33/client.Cs -> TS
The server closed the connection: fine once application data flows (many servers skip close_notify), an error during the handshake.
def fed source · line 92 · raw
@s:Socket -> @+cs2:0xb50db566077215d442e9798060f35e33/client.Cs -> @+cap:U32 -> @fr:0x475c2a8333a479bccfdd668aaa51426c/http.Fr -> @+seen:Nat -> TS
def after_bytes source · line 95 · raw
@n:Nat -> @s:Socket -> @+cs:0xb50db566077215d442e9798060f35e33/client.Cs -> @+bs:List<&2, U32> -> @+cap:U32 -> @fr:0x475c2a8333a479bccfdd668aaa51426c/http.Fr -> @+seen:Nat -> TS
def after_recv source · line 102 · raw
@got:Pair(Socket, Result<&1, &1, Pair(U32, String), List<&2, U32>>) -> @+cs:0xb50db566077215d442e9798060f35e33/client.Cs -> @+cap:U32 -> @fr:0x475c2a8333a479bccfdd668aaa51426c/http.Fr -> @+seen:Nat -> TS
def sock_of source · line 113 · raw
@sent:Pair(Socket, Result<&1, &1, Pair(U32, String), Unit>) -> Socket
def closed source · line 127 · raw
@s:Socket -> @r:Result<&1, &1, Pair(U32, String), List<&2, U32>> -> IO(Ended)
def app_phase source · line 132 · raw
@p:0xb50db566077215d442e9798060f35e33/client.Phase -> Bool
def kept source · line 141 · raw
@ok:Bool -> @s:Socket -> @+cs:0xb50db566077215d442e9798060f35e33/client.Cs -> IO(Ended)
def stop source · line 148 · raw
@st:TS -> @+keep:Bool -> IO(Ended)
def loop source · line 159 · raw
@k:Nat -> @st:TS -> @+cap:U32 -> @+keep:Bool -> IO(Ended)
def random_done source · line 178 · raw
@got:Pair(File, Result<&1, &1, Pair(U32, String), List<&2, U32>>) -> IO(List<&2, U32>)
def random_bytes source · line 186 · raw
@n:U32 -> IO(List<&2, U32>)
def close_after source · line 195 · raw
@got:Pair(File, Result<&1, &1, Pair(U32, String), String>) -> IO(String)
def read_opened source · line 203 · raw
@r:Result<&1, &1, Pair(U32, String), File> -> @alt:IO(String) -> IO(String)
def read_or source · line 214 · raw
@path:String -> @alt:IO(String) -> IO(String)
The file's text, or alt when it does not open.
def system_bundle source · line 220 · raw
IO(String)
def bundle_at source · line 225 · raw
@r:Result<&1, &1, Pair(U32, String), String> -> IO(String)
def ca_bundle source · line 234 · raw
IO(String)
SSL_CERT_FILE (OpenSSL's convention) names the bundle to trust instead; when it is set but does not open, nothing is trusted.
def roots_now source · line 255 · raw
IO(List<&2, 0xd276682e9f8b76d0870e36f1d43799d6/cert.Cert>)
def loaded_of source · line 260 · raw
@rs:List<&2, 0xd276682e9f8b76d0870e36f1d43799d6/cert.Cert> -> IO(Store)
def store_of source · line 264 · raw
@verify:Bool -> @now:Bool -> IO(Store)
verify off: Unverified; verify on and now: the roots parsed here, once.
def trust_with source · line 275 · raw
@+check:Bool -> @rs:List<&2, 0xd276682e9f8b76d0870e36f1d43799d6/cert.Cert> -> @+host:String -> IO(0xb50db566077215d442e9798060f35e33/client.Trust)
def trust_for source · line 280 · raw
@st:Store -> @+host:String -> IO(0xb50db566077215d442e9798060f35e33/client.Trust)
def tls_sock source · line 291 · raw
@r:Result<&1, &1, Pair(U32, String), Socket> -> @trust:0xb50db566077215d442e9798060f35e33/client.Trust -> @+host:String -> @rnd:List<&2, U32> -> @req:List<&2, U32> -> @+cap:U32 -> @+keep:Bool -> IO(Ended)
def tls_ip source · line 300 · raw
@r:Result<&1, &1, Pair(U32, String), String> -> @+port:U32 -> @trust:0xb50db566077215d442e9798060f35e33/client.Trust -> @+host:String -> @rnd:List<&2, U32> -> @req:List<&2, U32> -> @+cap:U32 -> @+keep:Bool -> IO(Ended)
A host that does not resolve or a port that refuses is the request's error, never the end of the program.
def fresh source · line 308 · raw
@+host:String -> @+port:U32 -> @req:List<&2, U32> -> @+cap:U32 -> @st:Store -> @+keep:Bool -> IO(Ended)
A new connection: resolve, connect, handshake, the request.
def result_of source · line 316 · raw
@e:Ended -> Result<&1, &1, Pair(U32, String), List<&2, U32>>
def per_host source · line 339 · raw
U32
def most_idle source · line 342 · raw
Nat
def open_n source · line 363 · raw
@os:List<&2, Open> -> @+key:String -> U32
def open_add source · line 372 · raw
@os:List<&2, Open> -> @+key:String -> @+d:U32 -> @+up:Bool -> List<&2, Open>
def took_i source · line 387 · raw
@i:Idle -> @r:TakeI -> TakeI
def idle_back source · line 392 · raw
@m:Maybe<&1, Sess> -> @+k:String -> @rest:List<&1, Idle> -> List<&1, Idle>
def idle_pick source · line 401 · raw
@hit:Bool -> @+k:String -> @s:Sess -> @r:TakeI -> TakeI
(the tail's answer is computed first and combined here: a match cannot look at String.eq, and a helper that recursed back would be mutual)
def take_idle source · line 410 · raw
@xs:List<&1, Idle> -> @+key:String -> TakeI
def took_w source · line 422 · raw
@w:Waiter -> @r:TakeW -> TakeW
def wait_back source · line 427 · raw
@m:Maybe<&1, Chan(Maybe<&1, Sess>)> -> @+k:String -> @rest:List<&1, Waiter> -> List<&1, Waiter>
def wait_pick source · line 434 · raw
@hit:Bool -> @+k:String -> @c:Chan(Maybe<&1, Sess>) -> @r:TakeW -> TakeW
def take_wait source · line 443 · raw
@xs:List<&1, Waiter> -> @+key:String -> TakeW
def on_take_slot source · line 453 · raw
@free:Bool -> @+key:String -> @reply:Chan(Maybe<&1, Sess>) -> @rest:List<&1, Idle> -> @+os:List<&2, Open> -> @ws:List<&1, Waiter> -> PS
a take: an idle session, else a free slot (None: open one), else wait
def on_take source · line 460 · raw
@r:TakeI -> @+key:String -> @reply:Chan(Maybe<&1, Sess>) -> @+os:List<&2, Open> -> @ws:List<&1, Waiter> -> PS
def idle_put source · line 471 · raw
@full:Bool -> @+key:String -> @s:Sess -> @ids:List<&1, Idle> -> @+os:List<&2, Open> -> @ws:List<&1, Waiter> -> PS
def counted_con source · line 482 · raw
@i:Idle -> @c:Counted -> Counted
def count_idle source · line 487 · raw
@xs:List<&1, Idle> -> Counted
def idle_counted source · line 494 · raw
@c:Counted -> @+key:String -> @s:Sess -> @+os:List<&2, Open> -> @ws:List<&1, Waiter> -> PS
def on_put source · line 500 · raw
@r:TakeW -> @+key:String -> @s:Sess -> @ids:List<&1, Idle> -> @+os:List<&2, Open> -> PS
a put: to the first waiter for its host, else idle (else closed: too many idle)
def on_gone source · line 510 · raw
@r:TakeW -> @+key:String -> @ids:List<&1, Idle> -> @+os:List<&2, Open> -> PS
a session gone: its slot to the first waiter (who opens one), else free
def pool_next source · line 519 · raw
@q:Maybe<&1, PAsk> -> @ids:List<&1, Idle> -> @+os:List<&2, Open> -> @ws:List<&1, Waiter> -> PS
def close_sess source · line 534 · raw
@x:Sess -> IO(Unit)
def do_effs source · line 539 · raw
@es:List<&1, Eff> -> IO(Unit)
def close_idle source · line 550 · raw
@xs:List<&1, Idle> -> IO(Unit)
def wake_all source · line 560 · raw
@xs:List<&1, Waiter> -> IO(Unit)
the end: idle sessions closed; each waiter told to open its own
def pool_serve source · line 569 · raw
@n:Nat -> @st:PS -> @+inbox:Chan(PAsk) -> IO(Unit)
def pool_start source · line 586 · raw
@+inbox:Chan(PAsk) -> IO(Unit)
A pool for one client: the store to pass down (every https GET through it shares connections) and the channel to end it with (pool_end).
def pool_end source · line 589 · raw
@+inbox:Chan(PAsk) -> IO(Unit)
def pooled source · line 592 · raw
@+base:Store -> @+inbox:Chan(PAsk) -> Store
def is_pooled source · line 595 · raw
@st:Store -> Bool
def unsent source · line 604 · raw
@r:Result<&1, &1, PAsk, Unit> -> IO(Unit)
def give_back source · line 617 · raw
@m:Maybe<&1, Sess> -> @+key:String -> @+inbox:Chan(PAsk) -> IO(Unit)
back to the pool: the session, or the slot it held (a send to a pool that ended fails and hands the ask back: the session is closed here)
def returned source · line 624 · raw
@e:Ended -> @+key:String -> @+inbox:Chan(PAsk) -> IO(Result<&1, &1, Pair(U32, String), List<&2, U32>>)
def close_m source · line 629 · raw
@m:Maybe<&1, Sess> -> IO(Unit)
def retry_empty source · line 636 · raw
@empty:Bool -> @+bs:List<&2, U32> -> @keep:Maybe<&1, Sess> -> @+host:String -> @+port:U32 -> @+req:List<&2, U32> -> @+cap:U32 -> @st:Store -> IO(Ended)
def retry_stale source · line 645 · raw
@e:Ended -> @+host:String -> @+port:U32 -> @+req:List<&2, U32> -> @+cap:U32 -> @st:Store -> IO(Ended)
a borrowed session the server had closed meanwhile: an error, or nothing came back; the request goes out once more on a new connection
def on_borrowed source · line 654 · raw
@x:Sess -> @+host:String -> @+port:U32 -> @+req:List<&2, U32> -> @+cap:U32 -> @st:Store -> IO(Ended)
def lent source · line 660 · raw
@m:Maybe<&1, Maybe<&1, Sess>> -> @+host:String -> @+port:U32 -> @+req:List<&2, U32> -> @+cap:U32 -> @st:Store -> IO(Ended)
def asked source · line 671 · raw
@ok:Result<&1, &1, PAsk, Unit> -> @+reply:Chan(Maybe<&1, Sess>) -> @+host:String -> @+port:U32 -> @+req:List<&2, U32> -> @+cap:U32 -> @st:Store -> IO(Ended)
def pooled_get source · line 678 · raw
@+host:String -> @+port:U32 -> @+req:List<&2, U32> -> @+cap:U32 -> @st:Store -> @+inbox:Chan(PAsk) -> IO(Result<&1, &1, Pair(U32, String), List<&2, U32>>)
def own source · line 688 · raw
@+host:String -> @+port:U32 -> @+req:List<&2, U32> -> @+cap:U32 -> @st:Store -> IO(Result<&1, &1, Pair(U32, String), List<&2, U32>>)
def get_or_own source · line 691 · raw
@get:Bool -> @+host:String -> @+port:U32 -> @+req:List<&2, U32> -> @+cap:U32 -> @st:Store -> @+inbox:Chan(PAsk) -> IO(Result<&1, &1, Pair(U32, String), List<&2, U32>>)
def https_get source · line 700 · raw
@+host:String -> @+port:U32 -> @+req:List<&2, U32> -> @+cap:U32 -> @st:Store -> IO(Result<&1, &1, Pair(U32, String), List<&2, U32>>)
GET over TLS: returns the raw HTTP response bytes. Through a pool when the store has one and the request is a GET; else a connection of its own.