|
@@ -2,10 +2,10 @@
|
|
|
-- Part of nodemcu-httpserver, knows how to send an HTTP header.
|
|
|
-- Author: Marcos Kirsch
|
|
|
|
|
|
-return function(connection, code, extension, isGzipped)
|
|
|
+return function(connection, code, extension, isGzipped, extraHeaders)
|
|
|
|
|
|
local function getHTTPStatusString(code)
|
|
|
- local codez = { [200] = "OK", [400] = "Bad Request", [404] = "Not Found", [500] = "Internal Server Error", }
|
|
|
+ local codez = { [200] = "OK", [400] = "Bad Request", [401] = "Unauthorized", [404] = "Not Found", [405] = "Method Not Allowed", [500] = "Internal Server Error", [501] = "Not Implemented", }
|
|
|
local myResult = codez[code]
|
|
|
-- enforce returning valid http codes all the way throughout?
|
|
|
if myResult then return myResult else return "Not Implemented" end
|
|
@@ -19,11 +19,19 @@ return function(connection, code, extension, isGzipped)
|
|
|
end
|
|
|
|
|
|
local mimeType = getMimeType(extension)
|
|
|
-
|
|
|
- connection:send("HTTP/1.0 " .. code .. " " .. getHTTPStatusString(code) .. "\r\nServer: nodemcu-httpserver\r\nContent-Type: " .. mimeType .. "\r\n")
|
|
|
+ local statusString = getHTTPStatusString(code)
|
|
|
+
|
|
|
+ connection:send("HTTP/1.0 " .. code .. " " .. statusString .. "\r\nServer: nodemcu-httpserver\r\nContent-Type: " .. mimeType .. "\r\n")
|
|
|
if isGzipped then
|
|
|
connection:send("Cache-Control: private, max-age=2592000\r\nContent-Encoding: gzip\r\n")
|
|
|
end
|
|
|
+ if (extraHeaders) then
|
|
|
+ for i, extraHeader in ipairs(extraHeaders) do
|
|
|
+ connection:send(extraHeader .. "\r\n")
|
|
|
+ end
|
|
|
+ end
|
|
|
+
|
|
|
connection:send("Connection: close\r\n\r\n")
|
|
|
+ return statusString
|
|
|
end
|
|
|
|