Diff

mod_websocket/mod_websocket.lua @ 856:7eb54ed58856

mod_websocket: Add CORS support
author Florian Zeitz <florob@babelmonkeys.de>
date Wed, 31 Oct 2012 20:07:23 +0100
parent 853:4d27552ac443
child 857:1393af36ec9c
line wrap: on
line diff
--- a/mod_websocket/mod_websocket.lua	Mon Oct 29 00:46:51 2012 +0100
+++ b/mod_websocket/mod_websocket.lua	Wed Oct 31 20:07:23 2012 +0100
@@ -33,6 +33,18 @@
 local opt_keepalives = module:get_option_boolean("tcp_keepalives", false);
 local self_closing_stream = module:get_option_boolean("websocket_self_closing_stream", true);
 
+local cross_domain = module:get_option("cross_domain_websocket");
+if cross_domain then
+	if cross_domain == true then
+		cross_domain = "*";
+	elseif type(cross_domain) == "table" then
+		cross_domain = table.concat(cross_domain, ", ");
+	end
+	if type(cross_domain) ~= "string" then
+		cross_domain = nil;
+	end
+end
+
 local sessions = module:shared("sessions");
 local core_process_stanza = prosody.core_process_stanza;
 
@@ -463,6 +475,7 @@
 	response.headers.Connection = "Upgrade";
 	response.headers.Sec_WebSocket_Accept = base64(sha1(request.headers.sec_websocket_key .. "258EAFA5-E914-47DA-95CA-C5AB0DC85B11"));
 	response.headers.Sec_WebSocket_Protocol = "xmpp";
+	response.headers.Access_Control_Allow_Origin = cross_domain;
 
 	return "";
 end