13.04.2023, 08:55
Try this:
Code:
local socket = require("socket")
local server = assert(socket.bind("*", 7777))
local crlf = '\r\n'
while true do
local client = server:accept()
client:settimeout(5)
local pat, len
while true do
local res, err = client:receive(pat)
if err then
break
end
if type(pat) == 'number' then
client:send(
'HTTP/1.1 200 OK' .. crlf ..
'Connection: close' .. crlf .. crlf
)
log(res) -- contains request body
break
elseif #res == 0 then
pat = len
elseif not len then
len = res:match('Content%-Length: (%d+)')
len = tonumber(len)
end
end
client:close()
end