From 1b4a2c9d9ab308f89c75b9b8304e3511f8cb1680 Mon Sep 17 00:00:00 2001 From: Marcos Kirsch Date: Sun, 21 Feb 2016 12:23:06 -0600 Subject: [PATCH] Concatenate .. less in lua since BufferedConnection will do it for us anyway: --- httpserver-error.lua | 7 +++---- httpserver-header.lua | 9 +++------ 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/httpserver-error.lua b/httpserver-error.lua index 77f2516..fd9e9ae 100644 --- a/httpserver-error.lua +++ b/httpserver-error.lua @@ -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 .. "" .. args.code .. " - " .. args.errorString .. "

" .. args.code .. " - " .. args.errorString .. "

\r\n" - connection:send(html) - html = nil + connection:send(getHeader(connection, args.code, args.errorString, args.headers, "text/html")) + connection:send("" .. args.code .. " - " .. args.errorString .. "

" .. args.code .. " - " .. args.errorString .. "

\r\n") end diff --git a/httpserver-header.lua b/httpserver-header.lua index 9f8f7bc..d218722 100644 --- a/httpserver-header.lua +++ b/httpserver-header.lua @@ -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