Frubi made me to make it RFC compatible
This commit is contained in:
parent
3cb00ff3df
commit
d1ad170955
@ -8,22 +8,26 @@ function sendPage(conn, nameOfFile)
|
|||||||
conn:on("sent", function(conn)
|
conn:on("sent", function(conn)
|
||||||
if (sentBytes == 0) then
|
if (sentBytes == 0) then
|
||||||
conn:close()
|
conn:close()
|
||||||
-- Clear the webpage generation
|
print("Page sent")
|
||||||
sendWebPage=nil
|
|
||||||
print("Clean webpage from RAM")
|
|
||||||
else
|
else
|
||||||
print("Send the next part of the file")
|
|
||||||
sendPage(conn, nameOfFile)
|
sendPage(conn, nameOfFile)
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
if file.open(nameOfFile, "r") then
|
if file.open(nameOfFile, "r") then
|
||||||
|
local buf=""
|
||||||
|
if (sentBytes <= 0) then
|
||||||
|
buf=buf .. "HTTP/1.1 200 OK\r\n"
|
||||||
|
buf=buf .. "Content-Type: text/html\r\n"
|
||||||
|
buf=buf .. "Connection: close\r\n"
|
||||||
|
buf=buf .. "Date: Thu, 29 Dec 2016 20:18:20 GMT\r\n"
|
||||||
|
buf=buf .. "\r\n\r\n"
|
||||||
|
end
|
||||||
-- amount of sent bytes is always zero at the beginning (so no problem)
|
-- amount of sent bytes is always zero at the beginning (so no problem)
|
||||||
file.seek("set", sentBytes)
|
file.seek("set", sentBytes)
|
||||||
|
|
||||||
local line = file.readline()
|
local line = file.readline()
|
||||||
-- TODO replace the tokens in the line
|
-- TODO replace the tokens in the line
|
||||||
local buf=""
|
|
||||||
while (line ~= nil) do
|
while (line ~= nil) do
|
||||||
buf = buf .. line
|
buf = buf .. line
|
||||||
-- increase the amount of sent bytes
|
-- increase the amount of sent bytes
|
||||||
@ -31,7 +35,6 @@ function sendPage(conn, nameOfFile)
|
|||||||
-- Sent after 1k data
|
-- Sent after 1k data
|
||||||
if (string.len(buf) >= 500) then
|
if (string.len(buf) >= 500) then
|
||||||
line=nil
|
line=nil
|
||||||
print("Send 500 bytes")
|
|
||||||
conn:send(buf)
|
conn:send(buf)
|
||||||
-- end the function, this part is sent
|
-- end the function, this part is sent
|
||||||
return
|
return
|
||||||
@ -93,8 +96,9 @@ function startWebServer()
|
|||||||
|
|
||||||
conn:on("disconnection", function(c)
|
conn:on("disconnection", function(c)
|
||||||
node.output(nil) -- un-register the redirect output function, output goes to serial
|
node.output(nil) -- un-register the redirect output function, output goes to serial
|
||||||
-- Reset Sent webpage
|
|
||||||
sendPage = nil
|
--reset amount of sent bytes, as we reached the end
|
||||||
|
sentBytes=0
|
||||||
end)
|
end)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user