# HG changeset patch # User Florian Zeitz # Date 1351710443 -3600 # Node ID 7eb54ed58856510c179bd409be0cf85a90b56817 # Parent 1983d4d51e1a3b3fae5c845c0a1faa240ead9d36 mod_websocket: Add CORS support diff -r 1983d4d51e1a -r 7eb54ed58856 mod_websocket/mod_websocket.lua --- 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