aboutsummaryrefslogtreecommitdiffstats
path: root/plugins/mod_http.lua
diff options
context:
space:
mode:
authorWaqas Hussain <waqas20@gmail.com>2012-04-21 17:38:48 +0500
committerWaqas Hussain <waqas20@gmail.com>2012-04-21 17:38:48 +0500
commit8d2bb74a6a3e34e09c0361d5f22e6df66c51c74d (patch)
treeb14bfa6555aea02353f4f249fa69a9599ca902e0 /plugins/mod_http.lua
parent59bd215bb29f37b2bbf809728f1d894a9ce112a4 (diff)
downloadprosody-8d2bb74a6a3e34e09c0361d5f22e6df66c51c74d.tar.gz
prosody-8d2bb74a6a3e34e09c0361d5f22e6df66c51c74d.zip
mod_http: Provide HTTP service.
Diffstat (limited to 'plugins/mod_http.lua')
-rw-r--r--plugins/mod_http.lua69
1 files changed, 69 insertions, 0 deletions
diff --git a/plugins/mod_http.lua b/plugins/mod_http.lua
new file mode 100644
index 00000000..4713cf13
--- /dev/null
+++ b/plugins/mod_http.lua
@@ -0,0 +1,69 @@
+-- Prosody IM
+-- Copyright (C) 2008-2010 Matthew Wild
+-- Copyright (C) 2008-2010 Waqas Hussain
+--
+-- This project is MIT/X11 licensed. Please see the
+-- COPYING file in the source package for more information.
+--
+
+module:set_global();
+
+--local sessions = module:shared("sessions");
+
+--[[function listener.associate_session(conn, session)
+ sessions[conn] = session;
+end]]
+
+local handlers;
+
+function build_handlers()
+ handlers = {};
+ for _, item in ipairs(module:get_host_items("http-handler")) do
+ local previous = handlers[item.path];
+ if not previous and item.path then
+ handlers[item.path] = item;
+ end
+ end
+end
+function clear_handlers()
+ handlers = nil;
+end
+module:handle_items("http-handler", clear_handlers, clear_handlers, false);
+
+function http_handler(event)
+ local request, response = event.request, event.response;
+
+ if not handlers then build_handlers(); end
+ local item = handlers[request.path:match("[^?]*")];
+ local handler = item and item.handler;
+ if handler then
+ handler(request, response);
+ return true;
+ end
+end
+
+local server = require "net.http.server";
+local listener = server.listener;
+server.add_handler("*", http_handler);
+function module.unload()
+ server.remove_handler("*", http_handler);
+end
+--require "net.http.server".listen_on(8080);
+
+module:add_item("net-provider", {
+ name = "http";
+ listener = listener;
+ default_port = 5280;
+ multiplex = {
+ pattern = "^[A-Z]";
+ };
+});
+
+module:add_item("net-provider", {
+ name = "https";
+ listener = listener;
+ encryption = "ssl";
+ multiplex = {
+ pattern = "^[A-Z]";
+ };
+});