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.
This commit is contained in:
@@ -33,6 +33,12 @@ static int callback_ws(struct lws* wsi, enum lws_callback_reasons reason,
|
|||||||
void* user, void* in, size_t len);
|
void* user, void* in, size_t len);
|
||||||
|
|
||||||
static const struct lws_protocols protocols[] = {
|
static const struct lws_protocols protocols[] = {
|
||||||
|
{
|
||||||
|
"http-only",
|
||||||
|
callback_ws,
|
||||||
|
sizeof(ControlServerData*),
|
||||||
|
0,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"dmf-control",
|
"dmf-control",
|
||||||
callback_ws,
|
callback_ws,
|
||||||
@@ -119,6 +125,25 @@ static int callback_ws(struct lws* wsi, enum lws_callback_reasons reason,
|
|||||||
return 0;
|
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)
|
ControlServer::ControlServer(uint16_t port, StatusCallback on_event)
|
||||||
: impl_(std::make_unique<Impl>()) {
|
: impl_(std::make_unique<Impl>()) {
|
||||||
impl_->port = port;
|
impl_->port = port;
|
||||||
@@ -129,6 +154,7 @@ ControlServer::ControlServer(uint16_t port, StatusCallback on_event)
|
|||||||
std::memset(&info, 0, sizeof(info));
|
std::memset(&info, 0, sizeof(info));
|
||||||
info.port = port;
|
info.port = port;
|
||||||
info.protocols = protocols;
|
info.protocols = protocols;
|
||||||
|
info.mounts = &mount;
|
||||||
info.user = impl_->data.get();
|
info.user = impl_->data.get();
|
||||||
info.gid = -1;
|
info.gid = -1;
|
||||||
info.uid = -1;
|
info.uid = -1;
|
||||||
|
|||||||
Reference in New Issue
Block a user