summaryrefslogtreecommitdiffstats
path: root/src/civetweb/test/echo.lua
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-27 18:24:20 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-27 18:24:20 +0000
commit483eb2f56657e8e7f419ab1a4fab8dce9ade8609 (patch)
treee5d88d25d870d5dedacb6bbdbe2a966086a0a5cf /src/civetweb/test/echo.lua
parentInitial commit. (diff)
downloadceph-483eb2f56657e8e7f419ab1a4fab8dce9ade8609.tar.xz
ceph-483eb2f56657e8e7f419ab1a4fab8dce9ade8609.zip
Adding upstream version 14.2.21.upstream/14.2.21upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/civetweb/test/echo.lua')
-rw-r--r--src/civetweb/test/echo.lua41
1 files changed, 41 insertions, 0 deletions
diff --git a/src/civetweb/test/echo.lua b/src/civetweb/test/echo.lua
new file mode 100644
index 00000000..bc715530
--- /dev/null
+++ b/src/civetweb/test/echo.lua
@@ -0,0 +1,41 @@
+
+if mg.lua_type ~= "websocket" then
+ mg.write("HTTP/1.0 403 Forbidden\r\n")
+ mg.write("Connection: close\r\n")
+ mg.write("\r\n")
+ mg.write("forbidden")
+ return
+end
+
+
+-- table of all active connection
+allConnections = {}
+
+-- function to get a client identification string
+function who(tab)
+ local ri = allConnections[tab.client].request_info
+ return ri.remote_addr .. ":" .. ri.remote_port
+end
+
+-- Callback to accept or reject a connection
+function open(tab)
+ allConnections[tab.client] = tab
+ return true -- return true to accept the connection
+end
+
+-- Callback for "Websocket ready"
+function ready(tab)
+ return true -- return true to keep the connection open
+end
+
+-- Callback for "Websocket received data"
+function data(tab)
+ mg.write(1, tab.data);
+ return true -- return true to keep the connection open
+end
+
+-- Callback for "Websocket is closing"
+function close(tab)
+ allConnections[tab.client] = nil
+end
+