diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 18:45:59 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 18:45:59 +0000 |
commit | 19fcec84d8d7d21e796c7624e521b60d28ee21ed (patch) | |
tree | 42d26aa27d1e3f7c0b8bd3fd14e7d7082f5008dc /src/civetweb/test/echo.lua | |
parent | Initial commit. (diff) | |
download | ceph-19fcec84d8d7d21e796c7624e521b60d28ee21ed.tar.xz ceph-19fcec84d8d7d21e796c7624e521b60d28ee21ed.zip |
Adding upstream version 16.2.11+ds.upstream/16.2.11+dsupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | src/civetweb/test/echo.lua | 41 |
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 000000000..bc715530f --- /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 + |