httpserver-error.lua 732 B

1234567891011121314
  1. -- httpserver-error.lua
  2. -- Part of nodemcu-httpserver, handles sending error pages to client.
  3. -- Author: Marcos Kirsch
  4. return function (connection, args)
  5. local function sendHeader(connection, code, errorString, mimeType)
  6. connection:send("HTTP/1.0 " .. code .. " " .. errorString .. "\r\nServer: nodemcu-httpserver\r\nContent-Type: " .. mimeType .. "\r\nConnection: close\r\n\r\n")
  7. end
  8. print("Error " .. args.code .. ": " .. args.errorString)
  9. sendHeader(connection, args.code, args.errorString, "text/html")
  10. connection:send("<html><head><title>" .. args.code .. " - " .. args.errorString .. "</title></head><body><h1>" .. args.code .. " - " .. args.errorString .. "</h1></body></html>\r\n")
  11. end