+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 = 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 = 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
+
+ if ssl then
+ ssl.mode = "server";
+ ssl.protocol = "sslv23";
+ ssl.options = "no_sslv2";
+ end
+
+ new{ port = port, interface = interface,
+ base = base, handler = handle_request,
+ ssl = ssl, type = (ssl and "ssl") or "tcp" };
+ end
+end
+