Websocket.head.loop: def of bend-kit-websocket@0.4.0.0 Import: import bend-kit-websocket@0.4.0.0/websocket.bend as Websocket Lines 803-837 of bend-kit-websocket@0.4.0.0/websocket.bend: https://jend.leeeet.dev/read.txt?path=bend-kit-websocket@0.4.0.0/websocket.bend&start_line=803&end_line=837 import Base import bend-kit-bytes@0.3.3.0/bytes.bend as Bytes def head.loop(n: Nat, h: Head, +tls: Bool, +ms: U32) -> IO(Socket & Result<&1, &1, U32 & String, String & Bytes.Bytes>): match n: case 0n: match h: case HRead{r, acc}: (sock, x) = r do IO>: return (sock, Fail{(1002, "HTTP head took too many reads")}) case HSplit{sock, s}: do IO>: return (sock, Fail{(1002, "HTTP head took too many reads")}) case 1n+p: match h: case HRead{r, acc}: match r: case (sock, Fail{e}): do IO>: return (sock, Fail{e}) case (sock, Done{(0, buf)}): do IO>: return (sock, Fail{(1006, "connection closed before the HTTP head ended")}) case (sock, Done{(+len, buf)}): head.loop(p, HSplit{sock, split(Bytes.append(acc, Bytes.Bytes{len, buf}))}, tls, ms) case HSplit{sock, s}: match s: case Found{head, rest}: do IO>: return (sock, Done{(head, rest)}) case Long{}: do IO>: return (sock, Fail{(1002, "HTTP head over 16 KiB")}) case Short{acc}: do IO>: r : Socket & Result<&1, &1, U32 & String, U32 & Array> <- io.recv(tls, sock, ms) head.loop(p, HRead{r, acc}, tls, ms) Uses (20): https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=Array https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=Bool https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=IO https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=IO.bind https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=IO.pure https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=Nat https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=Pair https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=Result https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=Sigma https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=Socket https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=String https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=U32 https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=Word.Con https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=Word.Nil https://jend.leeeet.dev/definition.txt?path=bend-kit-bytes@0.3.3.0/bytes.bend&name=Bytes https://jend.leeeet.dev/definition.txt?path=bend-kit-bytes@0.3.3.0/bytes.bend&name=append https://jend.leeeet.dev/definition.txt?path=bend-kit-websocket@0.4.0.0/websocket.bend&name=Head https://jend.leeeet.dev/definition.txt?path=bend-kit-websocket@0.4.0.0/websocket.bend&name=Split https://jend.leeeet.dev/definition.txt?path=bend-kit-websocket@0.4.0.0/websocket.bend&name=io.recv https://jend.leeeet.dev/definition.txt?path=bend-kit-websocket@0.4.0.0/websocket.bend&name=split