Software /
code /
prosody
Comparison
net/httpserver.lua @ 4164:843240294be1
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
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Wed, 23 Feb 2011 00:31:12 +0000 |
parent | 4161:c299726d2b4e |
child | 4165:9864f1375f3d |
comparison
equal
deleted
inserted
replaced
4163:bbfbdbc5e77e | 4164:843240294be1 |
---|---|
87 | 87 |
88 callback = (request.server and request.server.handlers[base]) or default_handler; | 88 callback = (request.server and request.server.handlers[base]) or default_handler; |
89 end | 89 end |
90 if callback then | 90 if callback then |
91 local _callback = callback; | 91 local _callback = callback; |
92 function callback(a, b, c) | 92 function callback(method, body, request) |
93 local status, result = xpcall(function() _callback(a, b, c) end, debug_traceback); | 93 local ok, result = xpcall(function() return _callback(method, body, request) end, debug_traceback); |
94 if status then return result; end | 94 if ok then return result; end |
95 log("error", "Error in HTTP server handler: %s", result); | 95 log("error", "Error in HTTP server handler: %s", result); |
96 -- TODO: When we support pipelining, request.destroyed | |
97 -- won't be the right flag - we just want to see if there | |
98 -- has been a response to this request yet. | |
99 if not request.destroyed then | |
100 return { | |
101 status = "500 Internal Server Error"; | |
102 headers = { ["Content-Type"] = "text/plain" }; | |
103 body = "There was an error processing your request. See the error log for more details."; | |
104 }; | |
105 end | |
96 end | 106 end |
97 if err then | 107 if err then |
98 log("debug", "Request error: "..err); | 108 log("debug", "Request error: "..err); |
99 if not callback(nil, err, request) then | 109 if not callback(nil, err, request) then |
100 destroy_request(request); | 110 destroy_request(request); |