2022-12-17 20:16:10 (UTC-03:00)
Marcel Rodrigues <marcelgmr@gmail.com>
add default error message when HTTP status is not 200
diff --git a/src/app.lua b/src/app.lua index 9c48a34..1542ddf 100644 --- a/src/app.lua +++ b/src/app.lua @@ -40,7 +40,7 @@ local function new_app(routes) end end end - return "nothing here", 404, "Not found" + return "", 404, "Not found" end return obj end diff --git a/src/http.lua b/src/http.lua index 1c003d8..40ed167 100644 --- a/src/http.lua +++ b/src/http.lua @@ -87,6 +87,10 @@ local function build_response(data, status, reason, cookies) header = "Location: " .. data .. "\n" end header = header .. build_cookie_data(cookies) + -- it's nice to provide a minimal error message by default + if status ~= 200 and data == "" then + data = status.." "..reason.."\n" + end local fmt = "HTTP/1.1 %03d %s\r\n%s\r\n%s" return fmt:format(status, reason, header, data) end