From ce8fa4c24bc39c57a58c7df8e37b5ee437eeabff Mon Sep 17 00:00:00 2001 From: cpq Date: Tue, 18 Oct 2022 14:31:47 +0100 Subject: [PATCH] Echo WS CLOSE payload back --- mongoose.c | 5 +++-- src/ws.c | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/mongoose.c b/mongoose.c index 3be4fd44..05b7406b 100644 --- a/mongoose.c +++ b/mongoose.c @@ -5812,9 +5812,10 @@ static void mg_ws_cb(struct mg_connection *c, int ev, void *ev_data, if (final) mg_call(c, MG_EV_WS_MSG, &m); break; case WEBSOCKET_OP_CLOSE: - MG_DEBUG(("%lu Got WS CLOSE", c->id)); + MG_DEBUG(("%lu WS CLOSE", c->id)); mg_call(c, MG_EV_WS_CTL, &m); - mg_ws_send(c, "", 0, WEBSOCKET_OP_CLOSE); + // Echo the payload of the received CLOSE message back to the sender + mg_ws_send(c, m.data.ptr, m.data.len, WEBSOCKET_OP_CLOSE); c->is_draining = 1; break; default: diff --git a/src/ws.c b/src/ws.c index eace26ef..f836cc7f 100644 --- a/src/ws.c +++ b/src/ws.c @@ -192,9 +192,10 @@ static void mg_ws_cb(struct mg_connection *c, int ev, void *ev_data, if (final) mg_call(c, MG_EV_WS_MSG, &m); break; case WEBSOCKET_OP_CLOSE: - MG_DEBUG(("%lu Got WS CLOSE", c->id)); + MG_DEBUG(("%lu WS CLOSE", c->id)); mg_call(c, MG_EV_WS_CTL, &m); - mg_ws_send(c, "", 0, WEBSOCKET_OP_CLOSE); + // Echo the payload of the received CLOSE message back to the sender + mg_ws_send(c, m.data.ptr, m.data.len, WEBSOCKET_OP_CLOSE); c->is_draining = 1; break; default: