-- httpserver-error.lua -- Part of nodemcu-httpserver, handles sending error pages to client. -- Author: Marcos Kirsch local function getHTTPStatusString(code) if code == 404 then return "Not Found" end if code == 400 then return "Bad Request" end if code == 501 then return "Not Implemented" end return "Unknown HTTP status" end local function sendHeader(connection, code, codeString, mimeType) connection:send("HTTP/1.0 " .. code .. " " .. codeString .. "\r\nServer: nodemcu-httpserver\r\nContent-Type: " .. mimeType .. "\r\nConnection: close\r\n\r\n") end return function (connection, args) errorString = getHTTPStatusString(args.code) print("Error: " .. args.code .. ": " .. errorString) sendHeader(connection, args.code, errorString, "text/html") connection:send("" .. args.code .. " - " .. errorString .. "

" .. args.code .. " - " .. errorString .. "

\r\n") end