# HG changeset patch # User Florian Zeitz # Date 1338159167 -7200 # Node ID 2de21fa403820b065c13045c7c18924cdb9c1fff # Parent 04662cc35280efaa1b647c8d763f2ce39ba15638 mod_websocket: Make sending a self-closing tag configurable Due to limitations in browser's XML parsers most (all?) existing client implementations require the tag to be self-closing. This commit makes this behaviour configurable, to enable "proper" implementations. diff -r 04662cc35280 -r 2de21fa40382 mod_websocket/mod_websocket.lua --- a/mod_websocket/mod_websocket.lua Sun May 27 19:30:37 2012 +0200 +++ b/mod_websocket/mod_websocket.lua Mon May 28 00:52:47 2012 +0200 @@ -31,6 +31,7 @@ local c2s_timeout = module:get_option_number("c2s_timeout"); local opt_keepalives = module:get_option_boolean("tcp_keepalives", false); +local self_closing_stream = module:get_option_boolean("websocket_self_closing_stream", true); local sessions = module:shared("sessions"); @@ -134,9 +135,15 @@ end -- COMPAT: Current client implementations need this to be self-closing - send(""..(tostring(st.stanza("stream:stream", { - xmlns = 'jabber:client', ["xmlns:stream"] = 'http://etherx.jabber.org/streams'; - id = session.streamid, from = session.host, version = '1.0', ["xml:lang"] = 'en' }):top_tag()):gsub(">", "/>"))); + if self_closing_stream then + send(""..tostring(st.stanza("stream:stream", { + xmlns = 'jabber:client', ["xmlns:stream"] = 'http://etherx.jabber.org/streams'; + id = session.streamid, from = session.host, version = '1.0', ["xml:lang"] = 'en' }))); + else + send(""..st.stanza("stream:stream", { + xmlns = 'jabber:client', ["xmlns:stream"] = 'http://etherx.jabber.org/streams'; + id = session.streamid, from = session.host, version = '1.0', ["xml:lang"] = 'en' }):top_tag()); + end (session.log or log)("debug", "Sent reply to client"); session.notopen = nil; @@ -199,8 +206,12 @@ local log = session.log or log; if session.conn then if session.notopen then - session.send(""); - session.send(st.stanza("stream:stream", default_stream_attr):top_tag()); + -- COMPAT: Current client implementations need this to be self-closing + if self_closing_stream then + session.send(""..tostring(st.stanza("stream:stream", default_stream_attr))); + else + session.send(""..st.stanza("stream:stream", default_stream_attr):top_tag()); + end end if reason then if type(reason) == "string" then -- assume stream error @@ -278,7 +289,9 @@ buffer = ""; -- COMPAT: Current client implementations send a self-closing - data = data:gsub("/>$", ">"); + if self_closing_stream then + data = data:gsub("/>$", ">"); + end data = filter("bytes/in", data); if data then