From d138478c1af7929a4a744861cf2872cc532d5a9b Mon Sep 17 00:00:00 2001 From: Johanness Date: Tue, 26 May 2026 01:40:42 +0300 Subject: [PATCH] fix: WebSocket control server - add HTTP mount for WS upgrade negotiation LWS v4.x requires an HTTP mount with LWSMPRO_CALLBACK to properly route WebSocket upgrade requests to the dmf-control protocol handler. Without this, WS connections were rejected with 403 Forbidden. --- libs/dmf-node/src/control_server.cpp | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/libs/dmf-node/src/control_server.cpp b/libs/dmf-node/src/control_server.cpp index 61c268a..7872757 100644 --- a/libs/dmf-node/src/control_server.cpp +++ b/libs/dmf-node/src/control_server.cpp @@ -33,6 +33,12 @@ static int callback_ws(struct lws* wsi, enum lws_callback_reasons reason, void* user, void* in, size_t len); static const struct lws_protocols protocols[] = { + { + "http-only", + callback_ws, + sizeof(ControlServerData*), + 0, + }, { "dmf-control", callback_ws, @@ -119,6 +125,25 @@ static int callback_ws(struct lws* wsi, enum lws_callback_reasons reason, return 0; } +static const struct lws_http_mount mount = { + .mount_next = nullptr, + .mountpoint = "/", + .origin = "", + .def = "", + .protocol = "dmf-control", + .cgienv = nullptr, + .extra_mimetypes = nullptr, + .interpret = nullptr, + .cgi_timeout = 0, + .cache_max_age = 0, + .auth_mask = 0, + .cache_reusable = 0, + .cache_revalidate = 0, + .cache_intermediaries = 0, + .origin_protocol = LWSMPRO_CALLBACK, + .mountpoint_len = 1, +}; + ControlServer::ControlServer(uint16_t port, StatusCallback on_event) : impl_(std::make_unique()) { impl_->port = port; @@ -129,6 +154,7 @@ ControlServer::ControlServer(uint16_t port, StatusCallback on_event) std::memset(&info, 0, sizeof(info)); info.port = port; info.protocols = protocols; + info.mounts = &mount; info.user = impl_->data.get(); info.gid = -1; info.uid = -1;