diff options
author | Matthew Wild <mwild1@gmail.com> | 2011-02-23 00:31:12 +0000 |
---|---|---|
committer | Matthew Wild <mwild1@gmail.com> | 2011-02-23 00:31:12 +0000 |
commit | e3d06ad37002b110f1c37ae46a80f3e707be4216 (patch) | |
tree | 93c245b25e7aa52bd7ecdbe2e826b429fcda341f /net | |
parent | aded42ab978d3cf76e638fbf69ad2c332c4cefe9 (diff) | |
download | prosody-e3d06ad37002b110f1c37ae46a80f3e707be4216.tar.gz prosody-e3d06ad37002b110f1c37ae46a80f3e707be4216.zip |
net.httpserver: Fix HTTP after commit c299726d2b4e and add a 500 error response if a request handler fails to make a response to the client
Diffstat (limited to 'net')
-rw-r--r-- | net/httpserver.lua | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/net/httpserver.lua b/net/httpserver.lua index 6d6408f7..36c04c3f 100644 --- a/net/httpserver.lua +++ b/net/httpserver.lua @@ -89,10 +89,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); |