From 9b5c6c4d9de2d32a3a0391e6d06a178f21dbb807 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Fri, 26 Oct 2018 19:32:00 +0100 Subject: Many things: switch from hacky multi-arg xpcall implementations to a standard util.xpcall --- net/http.lua | 7 ++++--- net/http/server.lua | 8 ++------ 2 files changed, 6 insertions(+), 9 deletions(-) (limited to 'net') diff --git a/net/http.lua b/net/http.lua index 6e5ad67c..b401b040 100644 --- a/net/http.lua +++ b/net/http.lua @@ -20,8 +20,9 @@ local ssl_available = pcall(require, "ssl"); local t_insert, t_concat = table.insert, table.concat; local pairs = pairs; -local tonumber, tostring, xpcall, traceback = - tonumber, tostring, xpcall, debug.traceback; +local tonumber, tostring, traceback = + tonumber, tostring, debug.traceback; +local xpcall = require "util.xpcall".xpcall; local error = error local setmetatable = setmetatable; @@ -101,7 +102,7 @@ function listener.onconnect(conn) end log("debug", "Request '%s': Calling callback, status %s", req.id, code or "---"); - return log_if_failed(req.id, xpcall(function () return callback(content, code, response, request) end, handleerr)); + return log_if_failed(req.id, xpcall(callback, handleerr, content, code, response, request)); end req.reader = request_reader; req.state = "status"; diff --git a/net/http/server.lua b/net/http/server.lua index b73f3385..7fbf6377 100644 --- a/net/http/server.lua +++ b/net/http/server.lua @@ -8,7 +8,7 @@ local os_date = os.date; local pairs = pairs; local s_upper = string.upper; local setmetatable = setmetatable; -local xpcall = xpcall; +local xpcall = require "util.xpcall".xpcall; local traceback = debug.traceback; local tostring = tostring; local cache = require "util.cache"; @@ -88,8 +88,6 @@ setmetatable(events._handlers, { }); local handle_request; -local _1, _2, _3; -local function _handle_request() return handle_request(_1, _2, _3); end local last_err; local function _traceback_handler(err) last_err = err; log("error", "Traceback[httpserver]: %s", traceback(tostring(err), 2)); end @@ -107,9 +105,7 @@ function listener.onconnect(conn) while sessions[conn] and #pending > 0 do local request = t_remove(pending); --log("debug", "process_next: %s", request.path); - --handle_request(conn, request, process_next); - _1, _2, _3 = conn, request, process_next; - if not xpcall(_handle_request, _traceback_handler) then + if not xpcall(handle_request, _traceback_handler, conn, request, process_next) then conn:write("HTTP/1.0 500 Internal Server Error\r\n\r\n"..events.fire_event("http-error", { code = 500, private_message = last_err })); conn:close(); end -- cgit v1.2.3