def request

bend-kit-websocket@0.4.0.0 · websocket.bend:88

import bend-kit-websocket@0.4.0.0/websocket.bend as Websocket
import Base
import bend-kit-bytes@0.3.3.0/bytes.bend as Bytes

88# The GET that asks to upgrade. host is the Host header (with :port when not the default);
89# path is the origin-form target ("/" and on, percent-encoded). A char outside visible
90# ASCII could split the head and inject headers, so it fails with EINVAL (22).
91def request(+host: String, +path: String, +key: String) -> Result<&1, &1, U32 & String, Bytes.Bytes>:
92  verdict(Bytes.Bytes,
93    first(reject(Bool.or(String.is_empty(host), Bool.not(visible(host))), 22, "host is not visible ASCII"),
94    first(reject(Bool.or(Bool.not(String.starts_with(path, "/")), Bool.not(visible(path))), 22, "path is not an origin-form target"),
95      reject(Bool.or(String.is_empty(key), Bool.not(visible(key))), 22, "key is not visible ASCII"))),
96    Bytes.from_string("GET " ++ path ++ " HTTP/1.1\r\nHost: " ++ host
97      ++ "\r\nUpgrade: websocket\r\nConnection: Upgrade\r\nSec-WebSocket-Key: " ++ key
98      ++ "\r\nSec-WebSocket-Version: 13\r\n\r\n"))

Uses (15)

Used by (1)