]]--
module("luci.httpd.module", package.seeall)
require("luci.util")
+require("luci.http.protocol")
require("ltn12")
-- Creates a failure reply
-function Handler.failure(self, message)
- response = {
- status = 500,
- headers = {
- ["Content-Type"] = "text/plain"
- }
- }
-
- sourceout = ltn12.source.string(message)
+function Handler.failure(self, code, message)
+ local response = Response(code, { ["Content-Type"] = "text/plain" })
+ local sourceout = ltn12.source.string(message)
return response, sourceout
end
-- Check for any errors
if not stat then
- response, sourceout = self:failure(response)
+ response, sourceout = self:failure(500, response)
end
-- Check data
if not luci.util.instanceof(response, Response) then
- response, sourceout = self:failure("Core error: Invalid module response!")
+ response, sourceout = self:failure(500, "Core error: Invalid module response!")
end
-- Process outgoing filters
end
end
- luci.http.push_response(request, status, response, sourceout, sinkout, sinkerr)
+ luci.http.protocol.push_response(request, response, sourceout, sinkout, sinkerr)
end
-- Handler Response
Response = luci.util.class()
-function Response.__init__(self, request, status, headers)
+function Response.__init__(self, status, headers)
self.status = tonumber(status) or 200
self.headers = (type(headers) == "table") and headers or {}
end
function Response.setstatus(self, status)
self.status = status
-end
-
-
--- Status codes
-statusmsg = {
- [200] = "OK",
- [404] = "Not Found",
- [500] = "Internal Server Error",
-}
\ No newline at end of file
+end
\ No newline at end of file