src/wire.bend

emerging-ezhttp@0.11.0.0 · 27 lines · 0 definitions

1# ezhttp/src/wire: one request out and one response back. TLS and DNS stay in
2# the effect (OpenSSL via dlopen); this module does not re-specify TLS.
3#
4# Spec: scheme, host, port each on their own line; everything after the third
5# newline is the request verbatim; the scheme line may carry a timeout
6# (wirespec.bend). Answer: status on the first line, then text
7# ("0" and the raw response, or a non-zero code and the reason).
8import Base
9import emerging-ezhttp@0.11.0.0/src/wirespec.bend as Spec
10
11# the exchange
12def ezwire.talk(spec: String) -> IO(String):
13  import "./effs/wire.c"
14  import "./effs/wire.js"
15
16# the spec the effect reads (wirespec.bend)
17def wire.spec(secure: Bool, host: String, port: U32, req: String) -> String:
18  Spec.wire.spec(secure, host, port, req)
19
20# a request sent to a host and its whole answer read back
21def wire.talk(secure: Bool, host: String, port: U32, req: String) -> IO(String):
22  ezwire.talk(wire.spec(secure, host, port, req))
23
24# the same exchange, bounded by a timeout in milliseconds
25def wire.talk.timed(secure: Bool, ms: U32, host: String, port: U32,
26  req: String) -> IO(String):
27  ezwire.talk(Spec.wire.spec.timed(secure, ms, host, port, req))