From 05d7b7c8bc6f9547e3745eb18ba5f068e8a5148d Mon Sep 17 00:00:00 2001
From: Sergey Lyubka <valenok@gmail.com>
Date: Wed, 9 Apr 2014 11:55:36 +0100
Subject: [PATCH] Added MG_WS_HANDSHAKE

---
 mongoose.c | 4 +++-
 mongoose.h | 2 +-
 2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/mongoose.c b/mongoose.c
index 4988cdc19..966178a07 100644
--- a/mongoose.c
+++ b/mongoose.c
@@ -2631,7 +2631,9 @@ static void send_websocket_handshake_if_requested(struct mg_connection *conn) {
         *key = mg_get_header(conn, "Sec-WebSocket-Key");
   if (ver != NULL && key != NULL) {
     conn->is_websocket = 1;
-    send_websocket_handshake(conn, key);
+    if (call_user(MG_CONN_2_CONN(conn), MG_WS_HANDSHAKE) == MG_FALSE) {
+      send_websocket_handshake(conn, key);
+    }
   }
 }
 
diff --git a/mongoose.h b/mongoose.h
index db22091ad..f2efd0528 100644
--- a/mongoose.h
+++ b/mongoose.h
@@ -67,7 +67,7 @@ enum mg_event {
   MG_REQUEST,     // If callback returns MG_FALSE, Mongoose continues with req
   MG_REPLY,       // If callback returns MG_FALSE, Mongoose closes connection
   MG_CLOSE,       // Connection is closed, callback return value is ignored
-  MG_LUA,         // Called before LSP page invoked
+  MG_WS_HANDSHAKE,  // New websocket connection, handshake request
   MG_HTTP_ERROR   // If callback returns MG_FALSE, Mongoose continues with err
 };
 typedef int (*mg_handler_t)(struct mg_connection *, enum mg_event);
-- 
GitLab