diff options
Diffstat (limited to 'net/httpserver.lua')
-rw-r--r-- | net/httpserver.lua | 25 |
1 files changed, 18 insertions, 7 deletions
diff --git a/net/httpserver.lua b/net/httpserver.lua index 57c8eede..3a54fd62 100644 --- a/net/httpserver.lua +++ b/net/httpserver.lua @@ -61,7 +61,7 @@ local function send_response(request, response) end else -- Response we have is just a string (the body) - log("debug", "Sending response to %s: %s", request.id or "<none>", response or "<none>"); + log("debug", "Sending 200 response to %s", request.id or "<none>"); resp = { "HTTP/1.0 200 OK\r\n" }; t_insert(resp, "Connection: close\r\n"); @@ -89,9 +89,6 @@ local function call_callback(request, err) end callback = (request.server and request.server.handlers[base]) or default_handler; - if callback == default_handler then - log("debug", "Default callback for this request (base: "..tostring(base)..")") - end end if callback then if err then @@ -251,13 +248,27 @@ function new(params) end end -function new_from_config(ports, default_base, handle_request) +function set_default_handler(handler) + default_handler = handler; +end + +function new_from_config(ports, handle_request, default_options) + if type(handle_request) == "string" then -- COMPAT with old plugins + log("warn", "Old syntax of httpserver.new_from_config being used to register %s", handle_request); + handle_request, default_options = default_options, { base = handle_request }; + end for _, options in ipairs(ports) do - local port, base, ssl, interface = 5280, default_base, false, nil; + local port = default_options.port or 5280; + local base = default_options.base; + local ssl = default_options.ssl or false; + local interface = default_options.interface; if type(options) == "number" then port = options; elseif type(options) == "table" then - port, base, ssl, interface = options.port or 5280, options.path or default_base, options.ssl or false, options.interface; + port = options.port or port; + base = options.path or base; + ssl = options.ssl or ssl; + interface = options.interface or interface; elseif type(options) == "string" then base = options; end |