Server side : how to deny/reject a websocket handshake


My actions are: I added the MG_EV_WEBSOCKET_* hooks in my code.
My expectation & question is: I would like to know how the server-side may deny/reject a handshake request.
All the examples I viewed until now just simply accepted the request, returning from the main handler.
Is there a way to indicate to mongoose that the handshake was rejected. Through the pointer to the connection maybe?


The answer is: Catch MG_EV_WS_OPEN event, check whatever parameters you need to check, and set c->is_closing = 1; if you’d like a connection to close.

1 Like