Skip to content

Commit 6bc7801

Browse files
committed
ws: send sec-websocket-protocol: json (surrealdb v3+ requires explicit format)
1 parent 81763f2 commit 6bc7801

2 files changed

Lines changed: 16 additions & 4 deletions

File tree

src/transport_ws.jl

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,17 @@ function _ws_reconnect_loop(conn::RemoteWSConnection)
3434
attempt += 1
3535

3636
try
37-
# `require_ssl_verification` propagates to HTTP.jl's TLS layer
38-
# via WebSockets.open's kwargs forwarding. Defaults to verify on;
39-
# tests with self-signed certs flip it via the `tls_verify`
40-
# connect kwarg.
37+
# `subprotocol = "json"` sends `Sec-WebSocket-Protocol: json` on
38+
# the upgrade. SurrealDB 3.0+ requires the protocol format to be
39+
# explicit; v2.x inferred it. Without this, v3 servers accept
40+
# the upgrade then drop the first RPC mid-request (the SDK
41+
# surfaces it as `RPCError(-1): Connection lost mid-request`).
42+
#
43+
# `require_ssl_verification` propagates to HTTP.jl's TLS layer.
44+
# Defaults to verify on; tests with self-signed certs flip it
45+
# via the `tls_verify` connect kwarg.
4146
WebSockets.open(conn.url;
47+
subprotocol = "json",
4248
require_ssl_verification = conn.tls_verify) do ws
4349
conn.ws = ws
4450
attempt = 0 # consecutive-failure counter resets

test/mock_ws_server.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@ module MockWS
1414

1515
using WebSockets, Sockets, JSON, UUIDs
1616

17+
# SDK sends `Sec-WebSocket-Protocol: json` (required by SurrealDB v3+);
18+
# WebSockets.jl rejects upgrades with subprotocols not on the whitelist,
19+
# so register `json` here. Mirror this in any other test harness that
20+
# wraps WebSockets.upgrade.
21+
WebSockets.addsubproto("json")
22+
1723
mutable struct Mock
1824
port::Int
1925
listener::Sockets.TCPServer

0 commit comments

Comments
 (0)