Software /
code /
prosody
Comparison
plugins/mod_compression.lua @ 2283:156bb00ba5c0
mod_compression: Moving compression setup in a dedicated function.
author | Tobias Markmann <tm@ayena.de> |
---|---|
date | Sun, 29 Nov 2009 22:18:06 +0100 |
parent | 2282:6f54dac3ec2d |
child | 2284:491b89d6816b |
comparison
equal
deleted
inserted
replaced
2282:6f54dac3ec2d | 2283:156bb00ba5c0 |
---|---|
106 module:log("error", inflate_stream); | 106 module:log("error", inflate_stream); |
107 return | 107 return |
108 end | 108 end |
109 | 109 |
110 -- setup compression for session.w | 110 -- setup compression for session.w |
111 local old_send = session.send; | 111 local function setup_compression(session) |
112 local old_send = session.send; | |
112 | 113 |
113 session.send = function(t) | 114 session.send = function(t) |
114 local status, compressed, eof = pcall(deflate_stream, tostring(t), 'sync'); | 115 local status, compressed, eof = pcall(deflate_stream, tostring(t), 'sync'); |
115 if status == false then | 116 if status == false then |
116 session:close({ | 117 session:close({ |
117 condition = "undefined-condition"; | 118 condition = "undefined-condition"; |
118 text = compressed; | 119 text = compressed; |
119 extra = st.stanza("failure", {xmlns="http://jabber.org/protocol/compress"}):tag("processing-failed"); | 120 extra = st.stanza("failure", {xmlns="http://jabber.org/protocol/compress"}):tag("processing-failed"); |
120 }); | 121 }); |
121 module:log("warn", compressed); | 122 module:log("warn", compressed); |
122 return; | 123 return; |
123 end | 124 end |
124 old_send(compressed); | 125 old_send(compressed); |
125 end; | 126 end; |
127 end | |
128 setup_compression(session); | |
126 | 129 |
127 -- setup decompression for session.data | 130 -- setup decompression for session.data |
128 local function setup_decompression(session) | 131 local function setup_decompression(session) |
129 local old_data = session.data | 132 local old_data = session.data |
130 session.data = function(conn, data) | 133 session.data = function(conn, data) |