Echo WS CLOSE payload back

This commit is contained in:
cpq 2022-10-18 14:31:47 +01:00
parent cfe2e83e6b
commit ce8fa4c24b
2 changed files with 6 additions and 4 deletions

View File

@ -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:

View File

@ -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: