Only one request at a time

This commit is contained in:
ollo 2019-04-03 20:23:07 +02:00
parent 7052c4c25a
commit 784a75241c

View File

@ -1,7 +1,7 @@
--TODO:
configFile="config.lua"
httpSending=false
sentBytes=0
function sendPage(conn, nameOfFile, replaceMap)
collectgarbage()
@ -11,8 +11,9 @@ function sendPage(conn, nameOfFile, replaceMap)
conn:close()
print("Page sent")
collectgarbage()
httpSending=false
else
print("Next")
collectgarbage()
sendPage(conn, nameOfFile, replaceMap)
end
end)
@ -32,7 +33,6 @@ function sendPage(conn, nameOfFile, replaceMap)
local line = file.readline()
while (line ~= nil) do
-- all placeholder begin with a $, so search for it in the current line
if (line:find("$") ~= nil) then
-- Replace the placeholder with the dynamic content
@ -43,6 +43,8 @@ function sendPage(conn, nameOfFile, replaceMap)
end
end
end
-- increase the amount of sent bytes
sentBytes=sentBytes+string.len(line)
@ -126,8 +128,14 @@ function startWebServer()
srv=net.createServer(net.TCP)
srv:listen(80,function(conn)
conn:on("receive", function(conn,payload)
if (httpSending) then
print("HTTP sending... be patient!")
return
end
if (payload:find("GET /") ~= nil) then
httpSending=true
--here is code for handling http request from a web-browser
collectgarbage()
@ -297,3 +305,4 @@ function startWebServer()
end)
end
--FileView done.