# HG changeset patch # User Marco Cirillo # Date 1335704786 0 # Node ID dfd7f1ed7782ea7161ae557edfe990d14f4a0ad8 # Parent 6f0e0d6790a7a906df31591471fa6b2e25363ea1 mod_server_status: updated to current HTTP API. diff -r 6f0e0d6790a7 -r dfd7f1ed7782 mod_server_status/mod_server_status.lua --- a/mod_server_status/mod_server_status.lua Sun Apr 29 13:05:46 2012 +0000 +++ b/mod_server_status/mod_server_status.lua Sun Apr 29 13:06:26 2012 +0000 @@ -1,14 +1,14 @@ -- (C) 2011, Marco Cirillo (LW.Org) -- Display server stats in readable XML or JSON format +module:depends("http") module:set_global() -local ports = module:get_option_array("server_status_http_ports", {{ port = 5280 }}) +local base_path = module:get_option_array("server_status_basepath", "/server-status/") local show_hosts = module:get_option_array("server_status_show_hosts", nil) local show_comps = module:get_option_array("server_status_show_comps", nil) local json_output = module:get_option_boolean("server_status_json", false) -local httpserver = require "net.httpserver" local json_encode = require "util.json".encode -- code begin @@ -20,8 +20,6 @@ return false end -local r_err = "\n\n\nProsody's Server Status - Error %s\n\n\n\n\n

%s

\n\n\n\n" - local response_table = {} response_table.header = '' response_table.doc_header = '' @@ -111,31 +109,23 @@ -- http handlers -local function response(code, r, h) - local response = { status = code, body = r } - - if h then response.headers = h end - return response -end - -local function request(method, body, request) - if method == "GET" then - if not json_output then return response(200, forge_response_xml()) else return response(200, forge_response_json()) end +local function request(event) + local response = event.response + if not json_output then + response.headers.content_type = "application/json" + response:send(forge_response_xml()) else - local err405 = r_err:format("405", "Only GET is supported") - return response(405, err405, {["Allow"] = "GET"}) + response.headers.content_type = "text/xml" + response:send(forge_response_json()) end end -- initialization. --- init http interface - -local function setup() - httpserver.new_from_config(ports, request, { base = "server-status" }) -end -if prosody.start_time then - setup() -else - module:hook("server-started", setup) -end +module:provides("http", { + default_path = base_path, + route = { + ["GET /"] = request + } +}) +