Changeset

7763:c5ce14539fc4

mod_websocket: Add the base URL of each host module is enabled on to 'cross_domain_websocket'
author Kim Alvefur <zash@zash.se>
date Mon, 05 Dec 2016 12:23:41 +0100
parents 7762:2208e6cd0d9f
children 7764:d6b96e42e8e6
files plugins/mod_websocket.lua
diffstat 1 files changed, 13 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/plugins/mod_websocket.lua	Mon Dec 05 12:22:41 2016 +0100
+++ b/plugins/mod_websocket.lua	Mon Dec 05 12:23:41 2016 +0100
@@ -315,4 +315,17 @@
 		};
 	});
 	module:hook("c2s-read-timeout", keepalive, -0.9);
+
+	if cross_domain ~= true then
+		local url = require "socket.url";
+		local ws_url = module:http_url("websocket", "xmpp-websocket");
+		local url_components = url.parse(ws_url);
+		-- The 'Origin' consists of the base URL without path
+		url_components.path = nil;
+		local this_origin = url.build(url_components);
+		cross_domain:add(this_origin);
+		function module.unload()
+			cross_domain:remove(this_origin);
+		end
+	end
 end