comparison 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
parents 4d27552ac443
children 1393af36ec9c
comparison
equal deleted inserted replaced
855:1983d4d51e1a 856:7eb54ed58856
30 30
31 local c2s_timeout = module:get_option_number("c2s_timeout"); 31 local c2s_timeout = module:get_option_number("c2s_timeout");
32 local stream_close_timeout = module:get_option_number("c2s_close_timeout", 5); 32 local stream_close_timeout = module:get_option_number("c2s_close_timeout", 5);
33 local opt_keepalives = module:get_option_boolean("tcp_keepalives", false); 33 local opt_keepalives = module:get_option_boolean("tcp_keepalives", false);
34 local self_closing_stream = module:get_option_boolean("websocket_self_closing_stream", true); 34 local self_closing_stream = module:get_option_boolean("websocket_self_closing_stream", true);
35
36 local cross_domain = module:get_option("cross_domain_websocket");
37 if cross_domain then
38 if cross_domain == true then
39 cross_domain = "*";
40 elseif type(cross_domain) == "table" then
41 cross_domain = table.concat(cross_domain, ", ");
42 end
43 if type(cross_domain) ~= "string" then
44 cross_domain = nil;
45 end
46 end
35 47
36 local sessions = module:shared("sessions"); 48 local sessions = module:shared("sessions");
37 local core_process_stanza = prosody.core_process_stanza; 49 local core_process_stanza = prosody.core_process_stanza;
38 50
39 local stream_callbacks = { default_ns = "jabber:client", handlestanza = core_process_stanza }; 51 local stream_callbacks = { default_ns = "jabber:client", handlestanza = core_process_stanza };
461 response.status = "101 Switching Protocols"; 473 response.status = "101 Switching Protocols";
462 response.headers.Upgrade = "websocket"; 474 response.headers.Upgrade = "websocket";
463 response.headers.Connection = "Upgrade"; 475 response.headers.Connection = "Upgrade";
464 response.headers.Sec_WebSocket_Accept = base64(sha1(request.headers.sec_websocket_key .. "258EAFA5-E914-47DA-95CA-C5AB0DC85B11")); 476 response.headers.Sec_WebSocket_Accept = base64(sha1(request.headers.sec_websocket_key .. "258EAFA5-E914-47DA-95CA-C5AB0DC85B11"));
465 response.headers.Sec_WebSocket_Protocol = "xmpp"; 477 response.headers.Sec_WebSocket_Protocol = "xmpp";
478 response.headers.Access_Control_Allow_Origin = cross_domain;
466 479
467 return ""; 480 return "";
468 end 481 end
469 482
470 function module.add_host(module) 483 function module.add_host(module)