Diff

mod_pubsub_post/mod_pubsub_post.lua @ 3018:727a8beeb5c3

mod_pubsub_post: Add an option for what to use as pubsub 'actor'
author Kim Alvefur <zash@zash.se>
date Sun, 20 May 2018 03:03:59 +0200
parent 3017:8e48c0b233e0
child 3254:af73963cf1dd
line wrap: on
line diff
--- a/mod_pubsub_post/mod_pubsub_post.lua	Sun May 20 02:56:48 2018 +0200
+++ b/mod_pubsub_post/mod_pubsub_post.lua	Sun May 20 03:03:59 2018 +0200
@@ -67,6 +67,8 @@
 	end
 end
 
+local actor_source = module:get_option_string("pubsub_post_actor", "superuser");
+
 function handle_POST(event, path)
 	local request = event.request;
 	module:log("debug", "Handling POST: \n%s\n", tostring(request.body));
@@ -74,6 +76,13 @@
 	local content_type = request.headers.content_type or "application/octet-stream";
 	local actor = true;
 
+	if actor_source == "request.ip" then
+		actor = request.ip or request.conn:ip();
+	elseif actor_source ~= "superuser" then
+		module:log("error", "pubsub_post_actor set to unsupported value %q", actor_source);
+		return 500;
+	end
+
 	if content_type == "application/xml" or content_type:sub(-4) == "+xml" then
 		return handle_xml(path, actor, request.body);
 	elseif content_type == "application/json" or content_type:sub(-5) == "+json" then