2023-07-15 15:24:15 (UTC-03:00)
Marcel Rodrigues <marcelgmr@gmail.com>
add Connection header in response
diff --git a/lib/ludweb/http.lua b/lib/ludweb/http.lua index e4c8363..cc7911a 100644 --- a/lib/ludweb/http.lua +++ b/lib/ludweb/http.lua @@ -77,7 +77,7 @@ local function build_cookie_data(cookies) return data end -local function build_response(data, status, reason, cookies) +local function build_response(data, status, reason, cookies, keep_alive) local header = "" if status == nil then status = 200 @@ -90,6 +90,11 @@ local function build_response(data, status, reason, cookies) if status ~= 200 and data == "" then data = status.." "..reason.."\n" end + if keep_alive then + header = header .. "Connection: keep-alive\r\n" + else + header = header .. "Connection: close\r\n" + end header = header .. "Content-Length: " .. #data .. "\r\n" header = header .. build_cookie_data(cookies) local fmt = "HTTP/1.1 %03d %s\r\n%s\r\n%s" @@ -113,8 +118,8 @@ local function new_http() if dataout == nil then return nil end - local resp = build_response(dataout, status, reason, cookies) local keep_alive = req.headers.connection ~= "close" + local resp = build_response(dataout, status, reason, cookies, keep_alive) return resp, keep_alive end return obj