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). 8 import Base 9 import ./wirespec.bend as Spec 10 11 # the exchange 12 def 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) 17 def 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 21 def 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 25 def 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))