Remove debug traces, handle long filenames
This commit is contained in:
parent
4f6cd02b1f
commit
a43fc20230
@ -69,9 +69,14 @@ return function (port)
|
||||
|
||||
local function onGet(connection, uri)
|
||||
local uri = parseUri(uri)
|
||||
local fileServeFunction = nil
|
||||
if #(uri.file) > 32 then
|
||||
-- nodemcu-firmware cannot handle long filenames.
|
||||
uri.args['code'] = 400
|
||||
fileServeFunction = dofile("httpserver-error.lc")
|
||||
else
|
||||
local fileExists = file.open(uri.file, "r")
|
||||
file.close()
|
||||
local fileServeFunction = nil
|
||||
if not fileExists then
|
||||
uri.args['code'] = 404
|
||||
fileServeFunction = dofile("httpserver-error.lc")
|
||||
@ -83,6 +88,7 @@ return function (port)
|
||||
uri.args['ext'] = uri.ext
|
||||
fileServeFunction = dofile("httpserver-static.lc")
|
||||
end
|
||||
end
|
||||
connectionThread = coroutine.create(fileServeFunction)
|
||||
--print("Thread created", connectionThread)
|
||||
coroutine.resume(connectionThread, connection, uri.args)
|
||||
@ -102,18 +108,15 @@ return function (port)
|
||||
local function onSent(connection, payload)
|
||||
local connectionThreadStatus = coroutine.status(connectionThread)
|
||||
-- print (connectionThread, "status is", connectionThreadStatus)
|
||||
if connectionThreadStatus == "dead" then
|
||||
-- We're done sending file.
|
||||
--print("Done sending file", connectionThread)
|
||||
connection:close()
|
||||
connectionThread = nil
|
||||
elseif connectionThreadStatus == "suspended" then
|
||||
if connectionThreadStatus == "suspended" then
|
||||
-- Not finished sending file, resume.
|
||||
-- print("Resume thread", connectionThread)
|
||||
coroutine.resume(connectionThread)
|
||||
else
|
||||
print ("Fatal error! I did not expect to hit this codepath")
|
||||
elseif connectionThreadStatus == "dead" then
|
||||
-- We're done sending file.
|
||||
-- print("Done thread", connectionThread)
|
||||
connection:close()
|
||||
connectionThread = nil
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user