add websockets echo server to redbean-tester

This commit is contained in:
Derek Meer 2025-03-21 14:13:44 -07:00
parent 8f4dc5a2af
commit ecb47384f8
2 changed files with 39 additions and 0 deletions

View file

@ -71,11 +71,17 @@ o/$(MODE)/test/tool/net/%.dbg: \
$(APE_NO_MODIFY_SELF)
@$(APELINK)
o/$(MODE)/tool/net/tester/.init.lua.zip.o: private \
ZIPOBJ_FLAGS += \
-B
.PRECIOUS: o/$(MODE)/test/tool/net/redbean-tester
o/$(MODE)/test/tool/net/redbean-tester.dbg: \
$(TOOL_NET_DEPS) \
o/$(MODE)/tool/net/redbean.o \
$(TOOL_NET_REDBEAN_LUA_MODULES) \
o/$(MODE)/tool/net/tester/.init.lua.zip.o \
o/$(MODE)/tool/net/demo/seekable.txt.zip.o \
o/$(MODE)/tool/net/net.pkg \
$(CRT) \

33
tool/net/tester/.init.lua Normal file
View file

@ -0,0 +1,33 @@
-- special script called by main redbean process at startup
HidePath('/usr/share/zoneinfo/')
HidePath('/usr/share/ssl/')
-- 20Ki, for certain autobahn tests
ProgramMaxPayloadSize(20 * 1024 * 1024)
function OnHttpRequest()
if GetPath() == "/ws" then
ws.Write(nil) -- upgrade without sending a response
coroutine.yield()
local fds = {[GetClientFd()] = unix.POLLIN}
-- simple echo server
while true do
unix.poll(fds)
local s, t = ws.Read()
if t == ws.CLOSE then
return
elseif t == ws.TEXT then
ws.Write(s, ws.TEXT)
coroutine.yield()
elseif t == ws.BIN then
ws.Write(s, ws.BIN)
coroutine.yield()
end
end
else
Route()
end
end