Repository navigation
Description
Net.HTTP.WebSocket (src/stdlib/net/http/websocket.kex) implements exactly one side of RFC 6455: WebSocket.connect(url) opens an outbound connection and returns a Connection with send, receiveMessage, session, close, closed?. There is no way to accept an incoming handshake — no upgrade response type, and no way for a Net.HTTP.Server route handler to take over the connection.
What's missing
Net.HTTP.Responseonly buildsbinary/text/empty— no upgrade/hijack response type.- The server-side intrinsic (
runtime/src/kex_intrinsic_nethttpserver.erl) has no upgrade path at all. kex_intrinsic_netwebsocket.erlis the client handshake exclusively (computesSec-WebSocket-Key, validatesSec-WebSocket-Accept) — nothing generates a server accept response or does server-side frame masking/validation.
This isn't a surprise gap — docs/net-plan.md already designs it and lists it as missing:
| WebSocket | Partial | Verified ws/wss client handshake, subprotocols, masked sends, fragmented high-level receive, UTF-8/close/limit checks, automatic pong | Server upgrades, raw frames, heartbeat, reconnecting client, scripted mock, browser implementation |
with a sketch of the intended shape (docs/net-plan.md:670-687):
router.get("/socket") do |request, context|
authenticate(request).map do |principal|
WebSocket.upgrade(request) do |handshake|
if handshake.subprotocols.contains?("chat.v2") then
Accept({ |socket| serveChat(principal, socket) }, headers: Headers.empty, subprotocol: Just("chat.v2"))
else
Reject(Response.text(426, "chat.v2 required"))
end
end
end
end
Why it matters
Found while scoping WebSocket route support for Rodolfo (kexhq/rodolfo), a small Sinatra/Kemal-inspired web framework — both of those frameworks support WebSocket routes, because their underlying servers (Rack's hijack API, Crystal's HTTP::Server upgrade) hand the framework the raw socket mid-request. Kex's Net.HTTP.Server has no equivalent hook, so a route handler can't take over the connection.
Net.Socket.TCP.listen/accept does give raw byte-level access, so a hand-rolled RFC 6455 server is technically reachable from application code today — but only as its own listener on a separate port, since there's no way to peek at a connection before Net.HTTP.Server claims it. Sharing one port with ordinary HTTP routes would mean reimplementing HTTP/1.1 request parsing from scratch, which isn't something a framework should have to do to get WebSocket support. Rodolfo route-level support (ws "/path" do |socket| ... end, mirroring get/post) is blocked on this landing in Kex.
Environment
Found against kex 0.4.0-beta.3 (293a0b5), both the version bundled at the time and a clean rebuild of origin/main at the same commit.
Activity
Mark #20/#22 fixed, correct #21's scope