local s_match, s_gmatch = string.match, string.gmatch;
local tonumber, tostring, pairs = tonumber, tostring, pairs;
-local urlcodes = setmetatable({}, { __index = function (t, k) t[k] = char(tonumber("0x"..k)); return t[k]; end });
-local urlencode = function (s) return s and (s:gsub("%W", function (c) return string.format("%%%x", c:byte()); end)); end
+local urlencode = function (s) return s and (s:gsub("%W", function (c) return string.format("%%%02x", c:byte()); end)); end
local log = require "util.logger".init("httpserver");
-- Write status line
local resp;
if response.body then
- log("debug", "Sending response to %s: %s", request.id, response.body);
+ log("debug", "Sending response to %s", request.id);
resp = { "HTTP/1.0 ", response.status or "200 OK", "\r\n"};
local h = response.headers;
if h then
local response = callback(request.method, request.body and t_concat(request.body), request);
if response then
- if response == true then
+ if response == true and not request.destroyed then
-- Keep connection open, we will reply later
log("warn", "Request %s left open, on_destroy is %s", request.id, tostring(request.on_destroy));
- else
+ elseif response ~= true then
-- Assume response
send_response(request, response);
destroy_request(request);