Concatenate .. less in lua since BufferedConnection will do it for us anyway:
This commit is contained in:
parent
11ae46c96b
commit
1b4a2c9d9a
@ -4,6 +4,7 @@
|
|||||||
|
|
||||||
return function (connection, req, args)
|
return function (connection, req, args)
|
||||||
|
|
||||||
|
-- @TODO: would be nice to use httpserver-header.lua
|
||||||
local function getHeader(connection, code, errorString, extraHeaders, mimeType)
|
local function getHeader(connection, code, errorString, extraHeaders, mimeType)
|
||||||
local header = "HTTP/1.0 " .. code .. " " .. errorString .. "\r\nServer: nodemcu-httpserver\r\nContent-Type: " .. mimeType .. "\r\n"
|
local header = "HTTP/1.0 " .. code .. " " .. errorString .. "\r\nServer: nodemcu-httpserver\r\nContent-Type: " .. mimeType .. "\r\n"
|
||||||
for i, extraHeader in ipairs(extraHeaders) do
|
for i, extraHeader in ipairs(extraHeaders) do
|
||||||
@ -15,9 +16,7 @@ return function (connection, req, args)
|
|||||||
|
|
||||||
print("Error " .. args.code .. ": " .. args.errorString)
|
print("Error " .. args.code .. ": " .. args.errorString)
|
||||||
args.headers = args.headers or {}
|
args.headers = args.headers or {}
|
||||||
local html = getHeader(connection, args.code, args.errorString, args.headers, "text/html")
|
connection:send(getHeader(connection, args.code, args.errorString, args.headers, "text/html"))
|
||||||
html = html .. "<html><head><title>" .. args.code .. " - " .. args.errorString .. "</title></head><body><h1>" .. args.code .. " - " .. args.errorString .. "</h1></body></html>\r\n"
|
connection:send("<html><head><title>" .. args.code .. " - " .. args.errorString .. "</title></head><body><h1>" .. args.code .. " - " .. args.errorString .. "</h1></body></html>\r\n")
|
||||||
connection:send(html)
|
|
||||||
html = nil
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
@ -19,14 +19,11 @@ return function (connection, code, extension, isGzipped)
|
|||||||
|
|
||||||
local mimeType = getMimeType(extension)
|
local mimeType = getMimeType(extension)
|
||||||
|
|
||||||
local header = "HTTP/1.0 " .. code .. " " .. getHTTPStatusString(code) .. "\r\nServer: nodemcu-httpserver\r\nContent-Type: " .. mimeType .. "\r\nnCache-Control: private, no-store\r\n"
|
connection:send("HTTP/1.0 " .. code .. " " .. getHTTPStatusString(code) .. "\r\nServer: nodemcu-httpserver\r\nContent-Type: " .. mimeType .. "\r\nnCache-Control: private, no-store\r\n")
|
||||||
if isGzipped then
|
if isGzipped then
|
||||||
header = header .. "Cache-Control: max-age=2592000\r\n"
|
connection:send("Cache-Control: max-age=2592000\r\nContent-Encoding: gzip\r\n")
|
||||||
header = header .. "Content-Encoding: gzip\r\n"
|
|
||||||
end
|
end
|
||||||
header = header .. "Connection: close\r\n\r\n"
|
connection:send("Connection: close\r\n\r\n")
|
||||||
connection:send(header)
|
|
||||||
header = nil
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user