# HG changeset patch # User Florian Zeitz # Date 1352336100 -3600 # Node ID 1393af36ec9cf9fe624f171bf311df6df366d0e5 # Parent 7eb54ed58856510c179bd409be0cf85a90b56817 mod_websocket: Determine whether to use a self-closing stream tag, based on the client's initial data diff -r 7eb54ed58856 -r 1393af36ec9c mod_websocket/mod_websocket.lua --- a/mod_websocket/mod_websocket.lua Wed Oct 31 20:07:23 2012 +0100 +++ b/mod_websocket/mod_websocket.lua Thu Nov 08 01:55:00 2012 +0100 @@ -31,7 +31,6 @@ local c2s_timeout = module:get_option_number("c2s_timeout"); local stream_close_timeout = module:get_option_number("c2s_close_timeout", 5); 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 @@ -154,8 +153,8 @@ return; end - -- COMPAT: Current client implementations need this to be self-closing - if self_closing_stream then + -- COMPAT: Some current client implementations need this to be self-closing + if session.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' }))); @@ -226,8 +225,8 @@ local log = session.log or log; if session.conn then if session.notopen then - -- COMPAT: Current client implementations need this to be self-closing - if self_closing_stream then + -- COMPAT: Some current client implementations need this to be self-closing + if session.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()); @@ -383,10 +382,9 @@ data = dataBuffer; dataBuffer = nil; - -- COMPAT: Current client implementations send a self-closing - if self_closing_stream then - data = data:gsub("($", "%1>"); - end + -- COMPAT: Some current client implementations send a self-closing + data, session.self_closing_stream = data:gsub("^($", "%1>"); + session.self_closing_stream = (session.self_closing_stream == 1) data = filter("bytes/in", data); if data then