Ouf enfin mon serveur web fonctionne sans perte de mémoire. Reste à faire maintenant la partie ASP ;-)

This commit is contained in:
Christian Zufferey
2019-01-27 10:49:25 +01:00
parent 34115b657f
commit ecf2829533
6 changed files with 43 additions and 110 deletions

View File

@@ -1,6 +1,6 @@
-- petit script de serveur WEB avec Active Server Page ZYX
print("\n web_srv2.lua zf190127.0145 \n")
print("\n web_srv2.lua zf190127.1045 \n")
-- send a file from memory to the client; max. line length = 1024 bytes!
function send_file(zclient, zfilename)
@@ -14,56 +14,40 @@ function send_file(zclient, zfilename)
until not line
file.close()
else
zclient:send("<html><h1>"..zfilename.." not found - 404 error.</h1><a href='/'>Home</a><br></html>")
zclient:send("<html><h1>"..zfilename.." not found - 404 error</h1><a href='/'>Home</a><br></html>")
end
zfilename = nil
zclient = nil
line = nil
file = nil
end
srv = net.createServer(net.TCP,10)
srv = net.createServer()
srv:listen(80, function(conn)
conn:on("receive", function(client, request)
_, _, method, path, vars = string.find(request, "([A-Z]+) (.+)?(.+) HTTP")
print("\n\nweb_srv debug")
print("request: \n---\n"..request.."---")
print("method: ",method)
print("path: ",path)
print("vars: ",vars)
--[[
if not string.find(request, "/favicon.ico") then
print("coucou")
if (method == nil) then
_, _, method, path = string.find(request, "([A-Z]+) (.+) HTTP")
end
_GET = {}
if (vars ~= nil) then
for k, v in string.gmatch(vars, "(%w+)=(%w+)&*") do
_GET[k] = v
print(k..": "..v)
end
end
file_html=string.gsub(path, "/", "")
print("file_html: ",file_html)
-- send_file(conn, file_html)
-- send_file = nil
]]
client:send("<h1> ESP8266<BR>Server is working!</h1>"..tmr.now().."\n\n")
conn:on("receive", function(client, request)
_, _, method, path, vars = string.find(request, "([A-Z]+) (.+)?(.+) HTTP")
-- print("\n\nweb_srv debug")
-- print("request: \n---\n"..request.."---")
-- print("method: ", method)
-- print("path: ", path)
-- print("vars: ", vars)
-- end
end)
conn:on("sent", function(c) c:close() end)
if not string.find(request, "/favicon.ico") then
print("coucou")
if (method == nil) then
_, _, method, path = string.find(request, "([A-Z]+) (.+) HTTP")
end
_GET = {}
if (vars ~= nil) then
for k, v in string.gmatch(vars, "(%w+)=(%w+)&*") do
_GET[k] = v
print(k..": "..v)
end
end
file_html=string.gsub(path, "/", "")
-- print("file_html: ",file_html)
send_file(client, file_html)
end
end)
conn:on("sent", function(c) c:close() end)
end)