aboutsummaryrefslogtreecommitdiffstats
path: root/net/httpserver.lua
diff options
context:
space:
mode:
authorMatthew Wild <mwild1@gmail.com>2009-07-12 15:23:39 +0100
committerMatthew Wild <mwild1@gmail.com>2009-07-12 15:23:39 +0100
commitc4841e0e92a8cce97c5fc3e689808aa4d63dc35a (patch)
treef8086a815fdbdd75e96a3092a58c6294af909b60 /net/httpserver.lua
parent04263369c807c434ebc9094723589098145beae5 (diff)
parent4117259212afab1c15f98eaeffb8c442cfa54c8c (diff)
downloadprosody-c4841e0e92a8cce97c5fc3e689808aa4d63dc35a.tar.gz
prosody-c4841e0e92a8cce97c5fc3e689808aa4d63dc35a.zip
Merge with 0.5
Diffstat (limited to 'net/httpserver.lua')
-rw-r--r--net/httpserver.lua22
1 files changed, 21 insertions, 1 deletions
diff --git a/net/httpserver.lua b/net/httpserver.lua
index d159202e..77cc5b98 100644
--- a/net/httpserver.lua
+++ b/net/httpserver.lua
@@ -17,7 +17,7 @@ local listener;
local t_insert, t_concat = table.insert, table.concat;
local s_match, s_gmatch = string.match, string.gmatch;
-local tonumber, tostring, pairs = tonumber, tostring, pairs;
+local tonumber, tostring, pairs, ipairs, type = tonumber, tostring, pairs, ipairs, type;
local urlencode = function (s) return s and (s:gsub("%W", function (c) return string.format("%%%02x", c:byte()); end)); end
@@ -250,6 +250,26 @@ function new(params)
end
end
+function new_from_config(ports, handle_request)
+ for _, options in ipairs(ports) do
+ local port, base, ssl, interface = 5280, "http-bind", false, nil;
+ if type(options) == "number" then
+ port = options;
+ elseif type(options) == "table" then
+ port, base, ssl, interface = options.port or 5280, options.path or "http-bind", options.ssl or false, options.interface;
+ elseif type(options) == "string" then
+ base = options;
+ end
+
+ if ssl then
+ ssl.mode = "server";
+ ssl.protocol = "sslv23";
+ end
+
+ new{ port = port, base = base, handler = handle_request, ssl = ssl, type = (ssl and "ssl") or "tcp" }
+ end
+end
+
_M.request_reader = request_reader;
_M.send_response = send_response;
_M.urlencode = urlencode;