Concatenate .. less in lua since BufferedConnection will do it for us anyway:

This commit is contained in:
Marcos Kirsch 2016-02-21 12:23:06 -06:00
parent 11ae46c96b
commit 1b4a2c9d9a
2 changed files with 6 additions and 10 deletions

View File

@ -4,6 +4,7 @@
return function (connection, req, args)
-- @TODO: would be nice to use httpserver-header.lua
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"
for i, extraHeader in ipairs(extraHeaders) do
@ -15,9 +16,7 @@ return function (connection, req, args)
print("Error " .. args.code .. ": " .. args.errorString)
args.headers = args.headers or {}
local html = 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)
html = nil
connection:send(getHeader(connection, args.code, args.errorString, args.headers, "text/html"))
connection:send("<html><head><title>" .. args.code .. " - " .. args.errorString .. "</title></head><body><h1>" .. args.code .. " - " .. args.errorString .. "</h1></body></html>\r\n")
end

View File

@ -19,14 +19,11 @@ return function (connection, code, extension, isGzipped)
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
header = header .. "Cache-Control: max-age=2592000\r\n"
header = header .. "Content-Encoding: gzip\r\n"
connection:send("Cache-Control: max-age=2592000\r\nContent-Encoding: gzip\r\n")
end
header = header .. "Connection: close\r\n\r\n"
connection:send(header)
header = nil
connection:send("Connection: close\r\n\r\n")
end