aboutsummaryrefslogtreecommitdiffstats
path: root/net/http.lua
diff options
context:
space:
mode:
authorMatthew Wild <mwild1@gmail.com>2016-07-07 23:12:25 +0100
committerMatthew Wild <mwild1@gmail.com>2016-07-07 23:12:25 +0100
commit02640bdb566f49709c408de4d8a10b42279a6431 (patch)
tree76eeece0bfac2413d8cc556ebafe560b82b6893c /net/http.lua
parentf4fed64125197c6c6ce830fcd7877c69876bfb50 (diff)
parent22ce4d182541dfd2699c0cb85f4f551d254d3ea3 (diff)
downloadprosody-02640bdb566f49709c408de4d8a10b42279a6431.tar.gz
prosody-02640bdb566f49709c408de4d8a10b42279a6431.zip
Merge 0.10->trunk
Diffstat (limited to 'net/http.lua')
-rw-r--r--net/http.lua18
1 files changed, 17 insertions, 1 deletions
diff --git a/net/http.lua b/net/http.lua
index b78f8438..669fa9a5 100644
--- a/net/http.lua
+++ b/net/http.lua
@@ -27,6 +27,8 @@ local _ENV = nil;
local requests = {}; -- Open requests
+local function make_id(req) return (tostring(req):match("%x+$")); end
+
local listener = { default_port = 80, default_mode = "*a" };
function listener.onconnect(conn)
@@ -113,6 +115,13 @@ local function request_reader(request, data, err)
end
local function handleerr(err) log("error", "Traceback[http]: %s", traceback(tostring(err), 2)); end
+local function log_if_failed(id, ret, ...)
+ if not ret then
+ log("error", "Request %s: error in callback: %s", id, tostring((...)));
+ end
+ return ...;
+end
+
local function request(u, ex, callback)
local req = url.parse(u);
@@ -125,6 +134,8 @@ local function request(u, ex, callback)
req.path = "/";
end
+ req.id = ex and ex.id or make_id(req);
+
local method, headers, body;
local host, port = req.host, req.port;
@@ -161,6 +172,8 @@ local function request(u, ex, callback)
end
end
+ log("debug", "Making %s %s request %s to %s", req.scheme, method or "GET", req.id, (ex and ex.suppress_url and host_header) or u);
+
-- Attach to request object
req.method, req.headers, req.body = method, headers, body;
@@ -183,7 +196,10 @@ local function request(u, ex, callback)
req.handler, req.conn = handler, conn
req.write = function (...) return req.handler:write(...); end
- req.callback = function (content, code, request, response) log("debug", "Calling callback, status %s", code or "---"); return select(2, xpcall(function () return callback(content, code, request, response) end, handleerr)); end
+ req.callback = function (content, code, request, response)
+ log("debug", "request %s: Calling callback, status %s", req.id, code or "---");
+ return log_if_failed(req.id, xpcall(function () return callback(content, code, request, response) end, handleerr));
+ end
req.reader = request_reader;
req.state = "status";