From 976b5f37c1b8592903a3a1d3e977078727bfa975 Mon Sep 17 00:00:00 2001
From: Sergey Lyubka <valenok@gmail.com>
Date: Sun, 9 Mar 2014 19:30:41 +0000
Subject: [PATCH] Added Lua callback

---
 mongoose.c | 2 ++
 mongoose.h | 1 +
 2 files changed, 3 insertions(+)

diff --git a/mongoose.c b/mongoose.c
index bf2b94056..b59909a95 100644
--- a/mongoose.c
+++ b/mongoose.c
@@ -3957,6 +3957,8 @@ static void handle_lsp_request(struct connection *conn, const char *path,
   } else {
     // We're not sending HTTP headers here, Lua page must do it.
     prepare_lua_environment(&conn->mg_conn, L);
+    conn->mg_conn.connection_param = L;
+    call_user(conn, MG_LUA);
     lua_pushcclosure(L, &lua_error_handler, 0);
     lua_rawgeti(L, LUA_REGISTRYINDEX, LUA_RIDX_GLOBALS);
     lsp(conn, p, (int) st->st_size, L);
diff --git a/mongoose.h b/mongoose.h
index 734147557..afde089da 100644
--- a/mongoose.h
+++ b/mongoose.h
@@ -66,6 +66,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
+  MG_LUA,         // Called before LSP page invoked
   MG_HTTP_ERROR   // If callback returns MG_FALSE, Mongoose continues with err
 };
 typedef int (*mg_handler_t)(struct mg_connection *, enum mg_event);
-- 
GitLab