typo fix at Cache-Control header, new http response code: 500 / internal server error

This commit is contained in:
Balazs Hollosi 2016-05-27 01:35:10 +02:00
parent 67e5ff5c20
commit 2b75289dfc

View File

@ -4,25 +4,25 @@
return function(connection, code, extension, isGzipped) return function(connection, code, extension, isGzipped)
local function getHTTPStatusString(code) 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", [404] = "Not Found", [500] = "Internal Server Error", }
local myResult = codez[code] local myResult = codez[code]
-- enforce returning valid http codes all the way throughout? -- enforce returning valid http codes all the way throughout?
if myResult then return myResult else return "Not Implemented" end if myResult then return myResult else return "Not Implemented" end
end end
local function getMimeType(ext) local function getMimeType(ext)
-- A few MIME types. Keep list short. If you need something that is missing, let's add it. -- A few MIME types. Keep list short. If you need something that is missing, let's add it.
local mt = { css = "text/css", gif = "image/gif", html = "text/html", ico = "image/x-icon", jpeg = "image/jpeg", jpg = "image/jpeg", js = "application/javascript", json = "application/json", png = "image/png", xml = "text/xml" } local mt = { css = "text/css", gif = "image/gif", html = "text/html", ico = "image/x-icon", jpeg = "image/jpeg", jpg = "image/jpeg", js = "application/javascript", json = "application/json", png = "image/png", xml = "text/xml" }
if mt[ext] then return mt[ext] else return "text/plain" end if mt[ext] then return mt[ext] else return "text/plain" end
end end
local mimeType = getMimeType(extension) local mimeType = getMimeType(extension)
connection:send("HTTP/1.0 " .. code .. " " .. getHTTPStatusString(code) .. "\r\nServer: nodemcu-httpserver\r\nContent-Type: " .. mimeType .. "\r\nCache-Control: private, no-store\r\n") connection:send("HTTP/1.0 " .. code .. " " .. getHTTPStatusString(code) .. "\r\nServer: nodemcu-httpserver\r\nContent-Type: " .. mimeType .. "\r\nCache-Control: private, no-store\r\n")
if isGzipped then if isGzipped then
connection:send("Cache-Control: max-age=2592000\r\nContent-Encoding: gzip\r\n") connection:send("Cache-Control: max-age=2592000\r\nContent-Encoding: gzip\r\n")
end end
connection:send("Connection: close\r\n\r\n") connection:send("Connection: close\r\n\r\n")
end end