aboutsummaryrefslogtreecommitdiffstats
path: root/net/http.lua
diff options
context:
space:
mode:
authorMatthew Wild <mwild1@gmail.com>2009-01-08 02:04:06 +0000
committerMatthew Wild <mwild1@gmail.com>2009-01-08 02:04:06 +0000
commit6b15ed47fd5bd8bc77186da4ef27384e933188c7 (patch)
tree0138408b4658d57598990db3d00bdaa35a721f96 /net/http.lua
parenta3661957b69b0e5ab9ddbcb28e7a06b9c5a30d0e (diff)
downloadprosody-6b15ed47fd5bd8bc77186da4ef27384e933188c7.tar.gz
prosody-6b15ed47fd5bd8bc77186da4ef27384e933188c7.zip
Protected call for HTTP request callbacks, to catch errors
Diffstat (limited to 'net/http.lua')
-rw-r--r--net/http.lua10
1 files changed, 7 insertions, 3 deletions
diff --git a/net/http.lua b/net/http.lua
index 64d83948..2ff88269 100644
--- a/net/http.lua
+++ b/net/http.lua
@@ -9,7 +9,10 @@ local connlisteners_get = require "net.connlisteners".get;
local listener = connlisteners_get("httpclient") or error("No httpclient listener!");
local t_insert, t_concat = table.insert, table.concat;
-local tonumber, tostring, pairs = tonumber, tostring, pairs;
+local tonumber, tostring, pairs, xpcall, select, debug_traceback =
+ tonumber, tostring, pairs, xpcall, select, debug.traceback;
+
+local log = require "util.logger".init("http");
local print = function () end
local urlcodes = setmetatable({}, { __index = function (t, k) t[k] = char(tonumber("0x"..k)); return t[k]; end });
@@ -105,6 +108,7 @@ local function request_reader(request, data, startpos)
end
end
+local function handleerr(err) log("error", "Traceback[http]: %s: %s", tostring(err), debug_traceback()); end
function request(u, ex, callback)
local req = url.parse(u);
@@ -157,9 +161,9 @@ function request(u, ex, callback)
req.write(body);
end
- req.callback = callback;
+ req.callback = function (content, code, request) log("debug", "Calling callback, code %s content: %s", code or "---", content or "---"); return select(2, xpcall(function () return callback(content, code, request) end, handleerr)); end
req.reader = request_reader;
- req.state = "status"
+ req.state = "status";
listener.register_request(req.handler, req);