Software /
code /
prosody
Comparison
plugins/mod_compression.lua @ 2883:adbca5af8536
mod_compression: Don't tell client compression succeeded when it didn't.
author | Waqas Hussain <waqas20@gmail.com> |
---|---|
date | Tue, 09 Mar 2010 17:52:18 +0500 |
parent | 2882:4e72048d4a24 |
child | 2884:6807f5fa0eb4 |
comparison
equal
deleted
inserted
replaced
2882:4e72048d4a24 | 2883:adbca5af8536 |
---|---|
46 end | 46 end |
47 | 47 |
48 -- checking if the compression method is supported | 48 -- checking if the compression method is supported |
49 local method = stanza:child_with_name("method")[1]; | 49 local method = stanza:child_with_name("method")[1]; |
50 if method == "zlib" then | 50 if method == "zlib" then |
51 session.log("info", method.." compression selected."); | |
52 session.send(st.stanza("compressed", {xmlns=xmlns_compression_protocol})); | |
53 session:reset_stream(); | |
54 | |
55 -- create deflate and inflate streams | 51 -- create deflate and inflate streams |
56 local status, deflate_stream = pcall(zlib.deflate, compression_level); | 52 local status, deflate_stream = pcall(zlib.deflate, compression_level); |
57 if status == false then | 53 if status == false then |
58 local error_st = st.stanza("failure", {xmlns=xmlns_compression_protocol}):tag("setup-failed"); | 54 local error_st = st.stanza("failure", {xmlns=xmlns_compression_protocol}):tag("setup-failed"); |
59 session.send(error_st); | 55 session.send(error_st); |
69 session.log("error", "Failed to create zlib.inflate filter."); | 65 session.log("error", "Failed to create zlib.inflate filter."); |
70 module:log("error", "%s", tostring(inflate_stream)); | 66 module:log("error", "%s", tostring(inflate_stream)); |
71 return | 67 return |
72 end | 68 end |
73 | 69 |
70 session.log("info", method.." compression selected."); | |
71 session.send(st.stanza("compressed", {xmlns=xmlns_compression_protocol})); | |
72 session:reset_stream(); | |
73 | |
74 -- setup compression for session.w | 74 -- setup compression for session.w |
75 local old_send = session.send; | 75 local old_send = session.send; |
76 | 76 |
77 session.send = function(t) | 77 session.send = function(t) |
78 local status, compressed, eof = pcall(deflate_stream, tostring(t), 'sync'); | 78 local status, compressed, eof = pcall(deflate_stream, tostring(t), 'sync'); |