diff --git a/test/tool/net/BUILD.mk b/test/tool/net/BUILD.mk index c1a7ebd4f..a1ac357b1 100644 --- a/test/tool/net/BUILD.mk +++ b/test/tool/net/BUILD.mk @@ -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) \ diff --git a/tool/net/tester/.init.lua b/tool/net/tester/.init.lua new file mode 100644 index 000000000..6fa68a912 --- /dev/null +++ b/tool/net/tester/.init.lua @@ -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 + +