net.dns: Support for resolving AAAA records
[prosody.git] / net / httpserver.lua
index 6d6408f76437e1e9e2043bd5d90f9c26f9f8906c..74f61c56a46182b27d654b6b17cfab77a8d6df73 100644 (file)
@@ -30,10 +30,6 @@ module "httpserver"
 
 local default_handler;
 
-local function expectbody(reqt)
-       return reqt.method == "POST";
-end
-
 local function send_response(request, response)
        -- Write status line
        local resp;
@@ -89,10 +85,20 @@ local function call_callback(request, err)
        end
        if callback then
                local _callback = callback;
-               function callback(a, b, c)
-                       local status, result = xpcall(function() _callback(a, b, c) end, debug_traceback);
-                       if status then return result; end
+               function callback(method, body, request)
+                       local ok, result = xpcall(function() return _callback(method, body, request) end, debug_traceback);
+                       if ok then return result; end
                        log("error", "Error in HTTP server handler: %s", result);
+                       -- TODO: When we support pipelining, request.destroyed
+                       -- won't be the right flag - we just want to see if there
+                       -- has been a response to this request yet.
+                       if not request.destroyed then
+                               return {
+                                       status = "500 Internal Server Error";
+                                       headers = { ["Content-Type"] = "text/plain" };
+                                       body = "There was an error processing your request. See the error log for more details.";
+                               };
+                       end
                end
                if err then
                        log("debug", "Request error: "..err);
@@ -130,7 +136,6 @@ local function request_reader(request, data, startpos)
                        call_callback(request);
                end
                local function error_cb(r)
-                       log("error", "Error in HTTP server handler: %s", r or "connection-closed");
                        call_callback(request, r or "connection-closed");
                        destroy_request(request);
                end