Software /
code /
prosody-modules
Annotate
mod_websocket/mod_websocket.lua @ 1025:b56a9aa171b3
mod_websocket: Fix length calculation
author | Florian Zeitz <florob@babelmonkeys.de> |
---|---|
date | Thu, 30 May 2013 22:48:19 +0200 |
parent | 969:8eba9d4809d2 |
child | 1026:e254cf49e14d |
rev | line source |
---|---|
676
54fa9d6d7809
mod_websocket: New mod_c2s based version, still WIP
Florian Zeitz <florob@babelmonkeys.de>
parents:
129
diff
changeset
|
1 -- Prosody IM |
54fa9d6d7809
mod_websocket: New mod_c2s based version, still WIP
Florian Zeitz <florob@babelmonkeys.de>
parents:
129
diff
changeset
|
2 -- Copyright (C) 2012 Florian Zeitz |
54fa9d6d7809
mod_websocket: New mod_c2s based version, still WIP
Florian Zeitz <florob@babelmonkeys.de>
parents:
129
diff
changeset
|
3 -- |
54fa9d6d7809
mod_websocket: New mod_c2s based version, still WIP
Florian Zeitz <florob@babelmonkeys.de>
parents:
129
diff
changeset
|
4 -- This project is MIT/X11 licensed. Please see the |
54fa9d6d7809
mod_websocket: New mod_c2s based version, still WIP
Florian Zeitz <florob@babelmonkeys.de>
parents:
129
diff
changeset
|
5 -- COPYING file in the source package for more information. |
54fa9d6d7809
mod_websocket: New mod_c2s based version, still WIP
Florian Zeitz <florob@babelmonkeys.de>
parents:
129
diff
changeset
|
6 -- |
54fa9d6d7809
mod_websocket: New mod_c2s based version, still WIP
Florian Zeitz <florob@babelmonkeys.de>
parents:
129
diff
changeset
|
7 |
54fa9d6d7809
mod_websocket: New mod_c2s based version, still WIP
Florian Zeitz <florob@babelmonkeys.de>
parents:
129
diff
changeset
|
8 module:set_global(); |
129 | 9 |
895
1f4d77104da5
mod_websocket: Simplify by getting the c2s_listener from mod_c2s
Florian Zeitz <florob@babelmonkeys.de>
parents:
857
diff
changeset
|
10 local add_filter = require "util.filters".add_filter; |
676
54fa9d6d7809
mod_websocket: New mod_c2s based version, still WIP
Florian Zeitz <florob@babelmonkeys.de>
parents:
129
diff
changeset
|
11 local sha1 = require "util.hashes".sha1; |
54fa9d6d7809
mod_websocket: New mod_c2s based version, still WIP
Florian Zeitz <florob@babelmonkeys.de>
parents:
129
diff
changeset
|
12 local base64 = require "util.encodings".base64.encode; |
895
1f4d77104da5
mod_websocket: Simplify by getting the c2s_listener from mod_c2s
Florian Zeitz <florob@babelmonkeys.de>
parents:
857
diff
changeset
|
13 local softreq = require "util.dependencies".softreq; |
1f4d77104da5
mod_websocket: Simplify by getting the c2s_listener from mod_c2s
Florian Zeitz <florob@babelmonkeys.de>
parents:
857
diff
changeset
|
14 local portmanager = require "core.portmanager"; |
676
54fa9d6d7809
mod_websocket: New mod_c2s based version, still WIP
Florian Zeitz <florob@babelmonkeys.de>
parents:
129
diff
changeset
|
15 |
905
eae665bc2122
mod_websocket: Fix require to work with lua-bitop (Thanks István and Zash)
Florian Zeitz <florob@babelmonkeys.de>
parents:
895
diff
changeset
|
16 local bit; |
eae665bc2122
mod_websocket: Fix require to work with lua-bitop (Thanks István and Zash)
Florian Zeitz <florob@babelmonkeys.de>
parents:
895
diff
changeset
|
17 pcall(function() bit = require"bit"; end); |
eae665bc2122
mod_websocket: Fix require to work with lua-bitop (Thanks István and Zash)
Florian Zeitz <florob@babelmonkeys.de>
parents:
895
diff
changeset
|
18 bit = bit or softreq"bit32" |
eae665bc2122
mod_websocket: Fix require to work with lua-bitop (Thanks István and Zash)
Florian Zeitz <florob@babelmonkeys.de>
parents:
895
diff
changeset
|
19 if not bit then module:log("error", "No bit module found. Either LuaJIT 2, lua-bitop or Lua 5.2 is required"); end |
895
1f4d77104da5
mod_websocket: Simplify by getting the c2s_listener from mod_c2s
Florian Zeitz <florob@babelmonkeys.de>
parents:
857
diff
changeset
|
20 local band = bit.band; |
1f4d77104da5
mod_websocket: Simplify by getting the c2s_listener from mod_c2s
Florian Zeitz <florob@babelmonkeys.de>
parents:
857
diff
changeset
|
21 local bxor = bit.bxor; |
910
c469a2b2d77d
mod_websocket: Avoid floating point division
Florian Zeitz <florob@babelmonkeys.de>
parents:
909
diff
changeset
|
22 local rshift = bit.rshift; |
676
54fa9d6d7809
mod_websocket: New mod_c2s based version, still WIP
Florian Zeitz <florob@babelmonkeys.de>
parents:
129
diff
changeset
|
23 |
856
7eb54ed58856
mod_websocket: Add CORS support
Florian Zeitz <florob@babelmonkeys.de>
parents:
853
diff
changeset
|
24 local cross_domain = module:get_option("cross_domain_websocket"); |
7eb54ed58856
mod_websocket: Add CORS support
Florian Zeitz <florob@babelmonkeys.de>
parents:
853
diff
changeset
|
25 if cross_domain then |
7eb54ed58856
mod_websocket: Add CORS support
Florian Zeitz <florob@babelmonkeys.de>
parents:
853
diff
changeset
|
26 if cross_domain == true then |
7eb54ed58856
mod_websocket: Add CORS support
Florian Zeitz <florob@babelmonkeys.de>
parents:
853
diff
changeset
|
27 cross_domain = "*"; |
7eb54ed58856
mod_websocket: Add CORS support
Florian Zeitz <florob@babelmonkeys.de>
parents:
853
diff
changeset
|
28 elseif type(cross_domain) == "table" then |
7eb54ed58856
mod_websocket: Add CORS support
Florian Zeitz <florob@babelmonkeys.de>
parents:
853
diff
changeset
|
29 cross_domain = table.concat(cross_domain, ", "); |
7eb54ed58856
mod_websocket: Add CORS support
Florian Zeitz <florob@babelmonkeys.de>
parents:
853
diff
changeset
|
30 end |
7eb54ed58856
mod_websocket: Add CORS support
Florian Zeitz <florob@babelmonkeys.de>
parents:
853
diff
changeset
|
31 if type(cross_domain) ~= "string" then |
7eb54ed58856
mod_websocket: Add CORS support
Florian Zeitz <florob@babelmonkeys.de>
parents:
853
diff
changeset
|
32 cross_domain = nil; |
7eb54ed58856
mod_websocket: Add CORS support
Florian Zeitz <florob@babelmonkeys.de>
parents:
853
diff
changeset
|
33 end |
7eb54ed58856
mod_websocket: Add CORS support
Florian Zeitz <florob@babelmonkeys.de>
parents:
853
diff
changeset
|
34 end |
7eb54ed58856
mod_websocket: Add CORS support
Florian Zeitz <florob@babelmonkeys.de>
parents:
853
diff
changeset
|
35 |
895
1f4d77104da5
mod_websocket: Simplify by getting the c2s_listener from mod_c2s
Florian Zeitz <florob@babelmonkeys.de>
parents:
857
diff
changeset
|
36 module:depends("c2s") |
1f4d77104da5
mod_websocket: Simplify by getting the c2s_listener from mod_c2s
Florian Zeitz <florob@babelmonkeys.de>
parents:
857
diff
changeset
|
37 local sessions = module:shared("c2s/sessions"); |
1f4d77104da5
mod_websocket: Simplify by getting the c2s_listener from mod_c2s
Florian Zeitz <florob@babelmonkeys.de>
parents:
857
diff
changeset
|
38 local c2s_listener = portmanager.get_service("c2s").listener; |
676
54fa9d6d7809
mod_websocket: New mod_c2s based version, still WIP
Florian Zeitz <florob@babelmonkeys.de>
parents:
129
diff
changeset
|
39 |
677
eeb41cd5e9f3
mod_websocket: Move frame handling into a separate function
Florian Zeitz <florob@babelmonkeys.de>
parents:
676
diff
changeset
|
40 -- Websocket helpers |
eeb41cd5e9f3
mod_websocket: Move frame handling into a separate function
Florian Zeitz <florob@babelmonkeys.de>
parents:
676
diff
changeset
|
41 local function parse_frame(frame) |
eeb41cd5e9f3
mod_websocket: Move frame handling into a separate function
Florian Zeitz <florob@babelmonkeys.de>
parents:
676
diff
changeset
|
42 local result = {}; |
eeb41cd5e9f3
mod_websocket: Move frame handling into a separate function
Florian Zeitz <florob@babelmonkeys.de>
parents:
676
diff
changeset
|
43 local pos = 1; |
eeb41cd5e9f3
mod_websocket: Move frame handling into a separate function
Florian Zeitz <florob@babelmonkeys.de>
parents:
676
diff
changeset
|
44 local length_bytes = 0; |
eeb41cd5e9f3
mod_websocket: Move frame handling into a separate function
Florian Zeitz <florob@babelmonkeys.de>
parents:
676
diff
changeset
|
45 local counter = 0; |
eeb41cd5e9f3
mod_websocket: Move frame handling into a separate function
Florian Zeitz <florob@babelmonkeys.de>
parents:
676
diff
changeset
|
46 local tmp_byte; |
eeb41cd5e9f3
mod_websocket: Move frame handling into a separate function
Florian Zeitz <florob@babelmonkeys.de>
parents:
676
diff
changeset
|
47 |
842
32df4d13f178
mod_websocket: More robust frame handling
Florian Zeitz <florob@babelmonkeys.de>
parents:
840
diff
changeset
|
48 if #frame < 2 then return; end |
32df4d13f178
mod_websocket: More robust frame handling
Florian Zeitz <florob@babelmonkeys.de>
parents:
840
diff
changeset
|
49 |
677
eeb41cd5e9f3
mod_websocket: Move frame handling into a separate function
Florian Zeitz <florob@babelmonkeys.de>
parents:
676
diff
changeset
|
50 tmp_byte = string.byte(frame, pos); |
eeb41cd5e9f3
mod_websocket: Move frame handling into a separate function
Florian Zeitz <florob@babelmonkeys.de>
parents:
676
diff
changeset
|
51 result.FIN = band(tmp_byte, 0x80) > 0; |
eeb41cd5e9f3
mod_websocket: Move frame handling into a separate function
Florian Zeitz <florob@babelmonkeys.de>
parents:
676
diff
changeset
|
52 result.RSV1 = band(tmp_byte, 0x40) > 0; |
eeb41cd5e9f3
mod_websocket: Move frame handling into a separate function
Florian Zeitz <florob@babelmonkeys.de>
parents:
676
diff
changeset
|
53 result.RSV2 = band(tmp_byte, 0x20) > 0; |
eeb41cd5e9f3
mod_websocket: Move frame handling into a separate function
Florian Zeitz <florob@babelmonkeys.de>
parents:
676
diff
changeset
|
54 result.RSV3 = band(tmp_byte, 0x10) > 0; |
690
5acc203972f3
mod_websocket: Add fragmentation support
Florian Zeitz <florob@babelmonkeys.de>
parents:
689
diff
changeset
|
55 result.opcode = band(tmp_byte, 0x0F); |
677
eeb41cd5e9f3
mod_websocket: Move frame handling into a separate function
Florian Zeitz <florob@babelmonkeys.de>
parents:
676
diff
changeset
|
56 |
eeb41cd5e9f3
mod_websocket: Move frame handling into a separate function
Florian Zeitz <florob@babelmonkeys.de>
parents:
676
diff
changeset
|
57 pos = pos + 1; |
eeb41cd5e9f3
mod_websocket: Move frame handling into a separate function
Florian Zeitz <florob@babelmonkeys.de>
parents:
676
diff
changeset
|
58 tmp_byte = string.byte(frame, pos); |
eeb41cd5e9f3
mod_websocket: Move frame handling into a separate function
Florian Zeitz <florob@babelmonkeys.de>
parents:
676
diff
changeset
|
59 result.MASK = band(tmp_byte, 0x80) > 0; |
eeb41cd5e9f3
mod_websocket: Move frame handling into a separate function
Florian Zeitz <florob@babelmonkeys.de>
parents:
676
diff
changeset
|
60 result.length = band(tmp_byte, 0x7F); |
eeb41cd5e9f3
mod_websocket: Move frame handling into a separate function
Florian Zeitz <florob@babelmonkeys.de>
parents:
676
diff
changeset
|
61 |
eeb41cd5e9f3
mod_websocket: Move frame handling into a separate function
Florian Zeitz <florob@babelmonkeys.de>
parents:
676
diff
changeset
|
62 if result.length == 126 then |
eeb41cd5e9f3
mod_websocket: Move frame handling into a separate function
Florian Zeitz <florob@babelmonkeys.de>
parents:
676
diff
changeset
|
63 length_bytes = 2; |
eeb41cd5e9f3
mod_websocket: Move frame handling into a separate function
Florian Zeitz <florob@babelmonkeys.de>
parents:
676
diff
changeset
|
64 result.length = 0; |
eeb41cd5e9f3
mod_websocket: Move frame handling into a separate function
Florian Zeitz <florob@babelmonkeys.de>
parents:
676
diff
changeset
|
65 elseif result.length == 127 then |
eeb41cd5e9f3
mod_websocket: Move frame handling into a separate function
Florian Zeitz <florob@babelmonkeys.de>
parents:
676
diff
changeset
|
66 length_bytes = 8; |
eeb41cd5e9f3
mod_websocket: Move frame handling into a separate function
Florian Zeitz <florob@babelmonkeys.de>
parents:
676
diff
changeset
|
67 result.length = 0; |
eeb41cd5e9f3
mod_websocket: Move frame handling into a separate function
Florian Zeitz <florob@babelmonkeys.de>
parents:
676
diff
changeset
|
68 end |
eeb41cd5e9f3
mod_websocket: Move frame handling into a separate function
Florian Zeitz <florob@babelmonkeys.de>
parents:
676
diff
changeset
|
69 |
842
32df4d13f178
mod_websocket: More robust frame handling
Florian Zeitz <florob@babelmonkeys.de>
parents:
840
diff
changeset
|
70 if #frame < (2 + length_bytes) then return; end |
32df4d13f178
mod_websocket: More robust frame handling
Florian Zeitz <florob@babelmonkeys.de>
parents:
840
diff
changeset
|
71 |
677
eeb41cd5e9f3
mod_websocket: Move frame handling into a separate function
Florian Zeitz <florob@babelmonkeys.de>
parents:
676
diff
changeset
|
72 for i = 1, length_bytes do |
eeb41cd5e9f3
mod_websocket: Move frame handling into a separate function
Florian Zeitz <florob@babelmonkeys.de>
parents:
676
diff
changeset
|
73 pos = pos + 1; |
840
f568661c9d39
mod_websocket: Fix frame length calculation
Florian Zeitz <florob@babelmonkeys.de>
parents:
839
diff
changeset
|
74 result.length = result.length * 256 + string.byte(frame, pos); |
677
eeb41cd5e9f3
mod_websocket: Move frame handling into a separate function
Florian Zeitz <florob@babelmonkeys.de>
parents:
676
diff
changeset
|
75 end |
eeb41cd5e9f3
mod_websocket: Move frame handling into a separate function
Florian Zeitz <florob@babelmonkeys.de>
parents:
676
diff
changeset
|
76 |
842
32df4d13f178
mod_websocket: More robust frame handling
Florian Zeitz <florob@babelmonkeys.de>
parents:
840
diff
changeset
|
77 if #frame < (2 + length_bytes + (result.MASK and 4 or 0) + result.length) then return; end |
32df4d13f178
mod_websocket: More robust frame handling
Florian Zeitz <florob@babelmonkeys.de>
parents:
840
diff
changeset
|
78 |
677
eeb41cd5e9f3
mod_websocket: Move frame handling into a separate function
Florian Zeitz <florob@babelmonkeys.de>
parents:
676
diff
changeset
|
79 if result.MASK then |
eeb41cd5e9f3
mod_websocket: Move frame handling into a separate function
Florian Zeitz <florob@babelmonkeys.de>
parents:
676
diff
changeset
|
80 result.key = {string.byte(frame, pos+1), string.byte(frame, pos+2), |
eeb41cd5e9f3
mod_websocket: Move frame handling into a separate function
Florian Zeitz <florob@babelmonkeys.de>
parents:
676
diff
changeset
|
81 string.byte(frame, pos+3), string.byte(frame, pos+4)} |
eeb41cd5e9f3
mod_websocket: Move frame handling into a separate function
Florian Zeitz <florob@babelmonkeys.de>
parents:
676
diff
changeset
|
82 |
eeb41cd5e9f3
mod_websocket: Move frame handling into a separate function
Florian Zeitz <florob@babelmonkeys.de>
parents:
676
diff
changeset
|
83 pos = pos + 5; |
eeb41cd5e9f3
mod_websocket: Move frame handling into a separate function
Florian Zeitz <florob@babelmonkeys.de>
parents:
676
diff
changeset
|
84 result.data = ""; |
eeb41cd5e9f3
mod_websocket: Move frame handling into a separate function
Florian Zeitz <florob@babelmonkeys.de>
parents:
676
diff
changeset
|
85 for i = pos, pos + result.length - 1 do |
eeb41cd5e9f3
mod_websocket: Move frame handling into a separate function
Florian Zeitz <florob@babelmonkeys.de>
parents:
676
diff
changeset
|
86 result.data = result.data .. string.char(bxor(result.key[counter+1], string.byte(frame, i))); |
eeb41cd5e9f3
mod_websocket: Move frame handling into a separate function
Florian Zeitz <florob@babelmonkeys.de>
parents:
676
diff
changeset
|
87 counter = (counter + 1) % 4; |
eeb41cd5e9f3
mod_websocket: Move frame handling into a separate function
Florian Zeitz <florob@babelmonkeys.de>
parents:
676
diff
changeset
|
88 end |
eeb41cd5e9f3
mod_websocket: Move frame handling into a separate function
Florian Zeitz <florob@babelmonkeys.de>
parents:
676
diff
changeset
|
89 else |
eeb41cd5e9f3
mod_websocket: Move frame handling into a separate function
Florian Zeitz <florob@babelmonkeys.de>
parents:
676
diff
changeset
|
90 result.data = frame:sub(pos + 1, pos + result.length); |
eeb41cd5e9f3
mod_websocket: Move frame handling into a separate function
Florian Zeitz <florob@babelmonkeys.de>
parents:
676
diff
changeset
|
91 end |
eeb41cd5e9f3
mod_websocket: Move frame handling into a separate function
Florian Zeitz <florob@babelmonkeys.de>
parents:
676
diff
changeset
|
92 |
842
32df4d13f178
mod_websocket: More robust frame handling
Florian Zeitz <florob@babelmonkeys.de>
parents:
840
diff
changeset
|
93 return result, 2 + length_bytes + (result.MASK and 4 or 0) + result.length; |
677
eeb41cd5e9f3
mod_websocket: Move frame handling into a separate function
Florian Zeitz <florob@babelmonkeys.de>
parents:
676
diff
changeset
|
94 end |
eeb41cd5e9f3
mod_websocket: Move frame handling into a separate function
Florian Zeitz <florob@babelmonkeys.de>
parents:
676
diff
changeset
|
95 |
687
d141375ece4b
mod_websocket: Move frame building into a function
Florian Zeitz <florob@babelmonkeys.de>
parents:
677
diff
changeset
|
96 local function build_frame(desc) |
d141375ece4b
mod_websocket: Move frame building into a function
Florian Zeitz <florob@babelmonkeys.de>
parents:
677
diff
changeset
|
97 local length; |
d141375ece4b
mod_websocket: Move frame building into a function
Florian Zeitz <florob@babelmonkeys.de>
parents:
677
diff
changeset
|
98 local result = ""; |
842
32df4d13f178
mod_websocket: More robust frame handling
Florian Zeitz <florob@babelmonkeys.de>
parents:
840
diff
changeset
|
99 local data = desc.data or ""; |
687
d141375ece4b
mod_websocket: Move frame building into a function
Florian Zeitz <florob@babelmonkeys.de>
parents:
677
diff
changeset
|
100 |
d141375ece4b
mod_websocket: Move frame building into a function
Florian Zeitz <florob@babelmonkeys.de>
parents:
677
diff
changeset
|
101 result = result .. string.char(0x80 * (desc.FIN and 1 or 0) + desc.opcode); |
d141375ece4b
mod_websocket: Move frame building into a function
Florian Zeitz <florob@babelmonkeys.de>
parents:
677
diff
changeset
|
102 |
842
32df4d13f178
mod_websocket: More robust frame handling
Florian Zeitz <florob@babelmonkeys.de>
parents:
840
diff
changeset
|
103 length = #data; |
687
d141375ece4b
mod_websocket: Move frame building into a function
Florian Zeitz <florob@babelmonkeys.de>
parents:
677
diff
changeset
|
104 if length <= 125 then -- 7-bit length |
d141375ece4b
mod_websocket: Move frame building into a function
Florian Zeitz <florob@babelmonkeys.de>
parents:
677
diff
changeset
|
105 result = result .. string.char(length); |
d141375ece4b
mod_websocket: Move frame building into a function
Florian Zeitz <florob@babelmonkeys.de>
parents:
677
diff
changeset
|
106 elseif length <= 0xFFFF then -- 2-byte length |
d141375ece4b
mod_websocket: Move frame building into a function
Florian Zeitz <florob@babelmonkeys.de>
parents:
677
diff
changeset
|
107 result = result .. string.char(126); |
910
c469a2b2d77d
mod_websocket: Avoid floating point division
Florian Zeitz <florob@babelmonkeys.de>
parents:
909
diff
changeset
|
108 result = result .. string.char(rshift(length, 8)) .. string.char(length%0x100); |
687
d141375ece4b
mod_websocket: Move frame building into a function
Florian Zeitz <florob@babelmonkeys.de>
parents:
677
diff
changeset
|
109 else -- 8-byte length |
1025
b56a9aa171b3
mod_websocket: Fix length calculation
Florian Zeitz <florob@babelmonkeys.de>
parents:
969
diff
changeset
|
110 local length_bytes = {}; |
687
d141375ece4b
mod_websocket: Move frame building into a function
Florian Zeitz <florob@babelmonkeys.de>
parents:
677
diff
changeset
|
111 result = result .. string.char(127); |
1025
b56a9aa171b3
mod_websocket: Fix length calculation
Florian Zeitz <florob@babelmonkeys.de>
parents:
969
diff
changeset
|
112 for i = 8, 1, -1 do |
b56a9aa171b3
mod_websocket: Fix length calculation
Florian Zeitz <florob@babelmonkeys.de>
parents:
969
diff
changeset
|
113 length_bytes[i] = string.char(length % 0x100); |
b56a9aa171b3
mod_websocket: Fix length calculation
Florian Zeitz <florob@babelmonkeys.de>
parents:
969
diff
changeset
|
114 length = rshift(length, 8); |
687
d141375ece4b
mod_websocket: Move frame building into a function
Florian Zeitz <florob@babelmonkeys.de>
parents:
677
diff
changeset
|
115 end |
1025
b56a9aa171b3
mod_websocket: Fix length calculation
Florian Zeitz <florob@babelmonkeys.de>
parents:
969
diff
changeset
|
116 result = result .. table.concat(length_bytes, ""); |
687
d141375ece4b
mod_websocket: Move frame building into a function
Florian Zeitz <florob@babelmonkeys.de>
parents:
677
diff
changeset
|
117 end |
d141375ece4b
mod_websocket: Move frame building into a function
Florian Zeitz <florob@babelmonkeys.de>
parents:
677
diff
changeset
|
118 |
842
32df4d13f178
mod_websocket: More robust frame handling
Florian Zeitz <florob@babelmonkeys.de>
parents:
840
diff
changeset
|
119 result = result .. data; |
687
d141375ece4b
mod_websocket: Move frame building into a function
Florian Zeitz <florob@babelmonkeys.de>
parents:
677
diff
changeset
|
120 |
d141375ece4b
mod_websocket: Move frame building into a function
Florian Zeitz <florob@babelmonkeys.de>
parents:
677
diff
changeset
|
121 return result; |
d141375ece4b
mod_websocket: Move frame building into a function
Florian Zeitz <florob@babelmonkeys.de>
parents:
677
diff
changeset
|
122 end |
d141375ece4b
mod_websocket: Move frame building into a function
Florian Zeitz <florob@babelmonkeys.de>
parents:
677
diff
changeset
|
123 |
895
1f4d77104da5
mod_websocket: Simplify by getting the c2s_listener from mod_c2s
Florian Zeitz <florob@babelmonkeys.de>
parents:
857
diff
changeset
|
124 --- Filter stuff |
1f4d77104da5
mod_websocket: Simplify by getting the c2s_listener from mod_c2s
Florian Zeitz <florob@babelmonkeys.de>
parents:
857
diff
changeset
|
125 function handle_request(event, path) |
1f4d77104da5
mod_websocket: Simplify by getting the c2s_listener from mod_c2s
Florian Zeitz <florob@babelmonkeys.de>
parents:
857
diff
changeset
|
126 local request, response = event.request, event.response; |
1f4d77104da5
mod_websocket: Simplify by getting the c2s_listener from mod_c2s
Florian Zeitz <florob@babelmonkeys.de>
parents:
857
diff
changeset
|
127 local conn = response.conn; |
676
54fa9d6d7809
mod_websocket: New mod_c2s based version, still WIP
Florian Zeitz <florob@babelmonkeys.de>
parents:
129
diff
changeset
|
128 |
895
1f4d77104da5
mod_websocket: Simplify by getting the c2s_listener from mod_c2s
Florian Zeitz <florob@babelmonkeys.de>
parents:
857
diff
changeset
|
129 if not request.headers.sec_websocket_key then |
1f4d77104da5
mod_websocket: Simplify by getting the c2s_listener from mod_c2s
Florian Zeitz <florob@babelmonkeys.de>
parents:
857
diff
changeset
|
130 response.headers.content_type = "text/html"; |
1f4d77104da5
mod_websocket: Simplify by getting the c2s_listener from mod_c2s
Florian Zeitz <florob@babelmonkeys.de>
parents:
857
diff
changeset
|
131 return [[<!DOCTYPE html><html><head><title>Websocket</title></head><body> |
1f4d77104da5
mod_websocket: Simplify by getting the c2s_listener from mod_c2s
Florian Zeitz <florob@babelmonkeys.de>
parents:
857
diff
changeset
|
132 <p>It works! Now point your WebSocket client to this URL to connect to Prosody.</p> |
1f4d77104da5
mod_websocket: Simplify by getting the c2s_listener from mod_c2s
Florian Zeitz <florob@babelmonkeys.de>
parents:
857
diff
changeset
|
133 </body></html>]]; |
676
54fa9d6d7809
mod_websocket: New mod_c2s based version, still WIP
Florian Zeitz <florob@babelmonkeys.de>
parents:
129
diff
changeset
|
134 end |
54fa9d6d7809
mod_websocket: New mod_c2s based version, still WIP
Florian Zeitz <florob@babelmonkeys.de>
parents:
129
diff
changeset
|
135 |
895
1f4d77104da5
mod_websocket: Simplify by getting the c2s_listener from mod_c2s
Florian Zeitz <florob@babelmonkeys.de>
parents:
857
diff
changeset
|
136 local wants_xmpp = false; |
1f4d77104da5
mod_websocket: Simplify by getting the c2s_listener from mod_c2s
Florian Zeitz <florob@babelmonkeys.de>
parents:
857
diff
changeset
|
137 (request.headers.sec_websocket_protocol or ""):gsub("([^,]*),?", function (proto) |
1f4d77104da5
mod_websocket: Simplify by getting the c2s_listener from mod_c2s
Florian Zeitz <florob@babelmonkeys.de>
parents:
857
diff
changeset
|
138 if proto == "xmpp" then wants_xmpp = true; end |
1f4d77104da5
mod_websocket: Simplify by getting the c2s_listener from mod_c2s
Florian Zeitz <florob@babelmonkeys.de>
parents:
857
diff
changeset
|
139 end); |
129 | 140 |
895
1f4d77104da5
mod_websocket: Simplify by getting the c2s_listener from mod_c2s
Florian Zeitz <florob@babelmonkeys.de>
parents:
857
diff
changeset
|
141 if not wants_xmpp then |
1f4d77104da5
mod_websocket: Simplify by getting the c2s_listener from mod_c2s
Florian Zeitz <florob@babelmonkeys.de>
parents:
857
diff
changeset
|
142 return 501; |
129 | 143 end |
144 | |
842
32df4d13f178
mod_websocket: More robust frame handling
Florian Zeitz <florob@babelmonkeys.de>
parents:
840
diff
changeset
|
145 local function websocket_close(code, message) |
910
c469a2b2d77d
mod_websocket: Avoid floating point division
Florian Zeitz <florob@babelmonkeys.de>
parents:
909
diff
changeset
|
146 local data = string.char(rshift(code, 8)) .. string.char(code%0x100) .. message; |
842
32df4d13f178
mod_websocket: More robust frame handling
Florian Zeitz <florob@babelmonkeys.de>
parents:
840
diff
changeset
|
147 conn:write(build_frame({opcode = 0x8, FIN = true, data = data})); |
32df4d13f178
mod_websocket: More robust frame handling
Florian Zeitz <florob@babelmonkeys.de>
parents:
840
diff
changeset
|
148 conn:close(); |
32df4d13f178
mod_websocket: More robust frame handling
Florian Zeitz <florob@babelmonkeys.de>
parents:
840
diff
changeset
|
149 end |
32df4d13f178
mod_websocket: More robust frame handling
Florian Zeitz <florob@babelmonkeys.de>
parents:
840
diff
changeset
|
150 |
32df4d13f178
mod_websocket: More robust frame handling
Florian Zeitz <florob@babelmonkeys.de>
parents:
840
diff
changeset
|
151 local dataBuffer; |
32df4d13f178
mod_websocket: More robust frame handling
Florian Zeitz <florob@babelmonkeys.de>
parents:
840
diff
changeset
|
152 local function handle_frame(frame) |
32df4d13f178
mod_websocket: More robust frame handling
Florian Zeitz <florob@babelmonkeys.de>
parents:
840
diff
changeset
|
153 module:log("debug", "Websocket received: %s (%i bytes)", frame.data, #frame.data); |
32df4d13f178
mod_websocket: More robust frame handling
Florian Zeitz <florob@babelmonkeys.de>
parents:
840
diff
changeset
|
154 |
32df4d13f178
mod_websocket: More robust frame handling
Florian Zeitz <florob@babelmonkeys.de>
parents:
840
diff
changeset
|
155 -- Error cases |
32df4d13f178
mod_websocket: More robust frame handling
Florian Zeitz <florob@babelmonkeys.de>
parents:
840
diff
changeset
|
156 if frame.RSV1 or frame.RSV2 or frame.RSV3 then -- Reserved bits non zero |
32df4d13f178
mod_websocket: More robust frame handling
Florian Zeitz <florob@babelmonkeys.de>
parents:
840
diff
changeset
|
157 websocket_close(1002, "Reserved bits not zero"); |
32df4d13f178
mod_websocket: More robust frame handling
Florian Zeitz <florob@babelmonkeys.de>
parents:
840
diff
changeset
|
158 return false; |
32df4d13f178
mod_websocket: More robust frame handling
Florian Zeitz <florob@babelmonkeys.de>
parents:
840
diff
changeset
|
159 end |
32df4d13f178
mod_websocket: More robust frame handling
Florian Zeitz <florob@babelmonkeys.de>
parents:
840
diff
changeset
|
160 |
32df4d13f178
mod_websocket: More robust frame handling
Florian Zeitz <florob@babelmonkeys.de>
parents:
840
diff
changeset
|
161 if frame.opcode >= 0x8 and frame.length > 125 then -- Control frame with too much payload |
32df4d13f178
mod_websocket: More robust frame handling
Florian Zeitz <florob@babelmonkeys.de>
parents:
840
diff
changeset
|
162 websocket_close(1002, "Payload too large"); |
32df4d13f178
mod_websocket: More robust frame handling
Florian Zeitz <florob@babelmonkeys.de>
parents:
840
diff
changeset
|
163 return false; |
32df4d13f178
mod_websocket: More robust frame handling
Florian Zeitz <florob@babelmonkeys.de>
parents:
840
diff
changeset
|
164 end |
32df4d13f178
mod_websocket: More robust frame handling
Florian Zeitz <florob@babelmonkeys.de>
parents:
840
diff
changeset
|
165 |
32df4d13f178
mod_websocket: More robust frame handling
Florian Zeitz <florob@babelmonkeys.de>
parents:
840
diff
changeset
|
166 if frame.opcode >= 0x8 and not frame.FIN then -- Fragmented control frame |
32df4d13f178
mod_websocket: More robust frame handling
Florian Zeitz <florob@babelmonkeys.de>
parents:
840
diff
changeset
|
167 websocket_close(1002, "Fragmented control frame"); |
32df4d13f178
mod_websocket: More robust frame handling
Florian Zeitz <florob@babelmonkeys.de>
parents:
840
diff
changeset
|
168 return false; |
32df4d13f178
mod_websocket: More robust frame handling
Florian Zeitz <florob@babelmonkeys.de>
parents:
840
diff
changeset
|
169 end |
690
5acc203972f3
mod_websocket: Add fragmentation support
Florian Zeitz <florob@babelmonkeys.de>
parents:
689
diff
changeset
|
170 |
842
32df4d13f178
mod_websocket: More robust frame handling
Florian Zeitz <florob@babelmonkeys.de>
parents:
840
diff
changeset
|
171 if (frame.opcode > 0x2 and frame.opcode < 0x8) or (frame.opcode > 0xA) then |
32df4d13f178
mod_websocket: More robust frame handling
Florian Zeitz <florob@babelmonkeys.de>
parents:
840
diff
changeset
|
172 websocket_close(1002, "Reserved opcode"); |
32df4d13f178
mod_websocket: More robust frame handling
Florian Zeitz <florob@babelmonkeys.de>
parents:
840
diff
changeset
|
173 return false; |
32df4d13f178
mod_websocket: More robust frame handling
Florian Zeitz <florob@babelmonkeys.de>
parents:
840
diff
changeset
|
174 end |
32df4d13f178
mod_websocket: More robust frame handling
Florian Zeitz <florob@babelmonkeys.de>
parents:
840
diff
changeset
|
175 |
32df4d13f178
mod_websocket: More robust frame handling
Florian Zeitz <florob@babelmonkeys.de>
parents:
840
diff
changeset
|
176 if frame.opcode == 0x0 and not dataBuffer then |
32df4d13f178
mod_websocket: More robust frame handling
Florian Zeitz <florob@babelmonkeys.de>
parents:
840
diff
changeset
|
177 websocket_close(1002, "Unexpected continuation frame"); |
32df4d13f178
mod_websocket: More robust frame handling
Florian Zeitz <florob@babelmonkeys.de>
parents:
840
diff
changeset
|
178 return false; |
32df4d13f178
mod_websocket: More robust frame handling
Florian Zeitz <florob@babelmonkeys.de>
parents:
840
diff
changeset
|
179 end |
32df4d13f178
mod_websocket: More robust frame handling
Florian Zeitz <florob@babelmonkeys.de>
parents:
840
diff
changeset
|
180 |
32df4d13f178
mod_websocket: More robust frame handling
Florian Zeitz <florob@babelmonkeys.de>
parents:
840
diff
changeset
|
181 if (frame.opcode == 0x1 or frame.opcode == 0x2) and dataBuffer then |
32df4d13f178
mod_websocket: More robust frame handling
Florian Zeitz <florob@babelmonkeys.de>
parents:
840
diff
changeset
|
182 websocket_close(1002, "Continuation frame expected"); |
32df4d13f178
mod_websocket: More robust frame handling
Florian Zeitz <florob@babelmonkeys.de>
parents:
840
diff
changeset
|
183 return false; |
32df4d13f178
mod_websocket: More robust frame handling
Florian Zeitz <florob@babelmonkeys.de>
parents:
840
diff
changeset
|
184 end |
32df4d13f178
mod_websocket: More robust frame handling
Florian Zeitz <florob@babelmonkeys.de>
parents:
840
diff
changeset
|
185 |
32df4d13f178
mod_websocket: More robust frame handling
Florian Zeitz <florob@babelmonkeys.de>
parents:
840
diff
changeset
|
186 -- Valid cases |
32df4d13f178
mod_websocket: More robust frame handling
Florian Zeitz <florob@babelmonkeys.de>
parents:
840
diff
changeset
|
187 if frame.opcode == 0x0 then -- Continuation frame |
32df4d13f178
mod_websocket: More robust frame handling
Florian Zeitz <florob@babelmonkeys.de>
parents:
840
diff
changeset
|
188 dataBuffer = dataBuffer .. frame.data; |
32df4d13f178
mod_websocket: More robust frame handling
Florian Zeitz <florob@babelmonkeys.de>
parents:
840
diff
changeset
|
189 elseif frame.opcode == 0x1 then -- Text frame |
32df4d13f178
mod_websocket: More robust frame handling
Florian Zeitz <florob@babelmonkeys.de>
parents:
840
diff
changeset
|
190 dataBuffer = frame.data; |
32df4d13f178
mod_websocket: More robust frame handling
Florian Zeitz <florob@babelmonkeys.de>
parents:
840
diff
changeset
|
191 elseif frame.opcode == 0x2 then -- Binary frame |
32df4d13f178
mod_websocket: More robust frame handling
Florian Zeitz <florob@babelmonkeys.de>
parents:
840
diff
changeset
|
192 websocket_close(1003, "Only text frames are supported"); |
895
1f4d77104da5
mod_websocket: Simplify by getting the c2s_listener from mod_c2s
Florian Zeitz <florob@babelmonkeys.de>
parents:
857
diff
changeset
|
193 return; |
842
32df4d13f178
mod_websocket: More robust frame handling
Florian Zeitz <florob@babelmonkeys.de>
parents:
840
diff
changeset
|
194 elseif frame.opcode == 0x8 then -- Close request |
32df4d13f178
mod_websocket: More robust frame handling
Florian Zeitz <florob@babelmonkeys.de>
parents:
840
diff
changeset
|
195 websocket_close(1000, "Goodbye"); |
895
1f4d77104da5
mod_websocket: Simplify by getting the c2s_listener from mod_c2s
Florian Zeitz <florob@babelmonkeys.de>
parents:
857
diff
changeset
|
196 return; |
691
04662cc35280
mod_websocket: Answer ping frames
Florian Zeitz <florob@babelmonkeys.de>
parents:
690
diff
changeset
|
197 elseif frame.opcode == 0x9 then -- Ping frame |
04662cc35280
mod_websocket: Answer ping frames
Florian Zeitz <florob@babelmonkeys.de>
parents:
690
diff
changeset
|
198 frame.opcode = 0xA; |
04662cc35280
mod_websocket: Answer ping frames
Florian Zeitz <florob@babelmonkeys.de>
parents:
690
diff
changeset
|
199 conn:write(build_frame(frame)); |
895
1f4d77104da5
mod_websocket: Simplify by getting the c2s_listener from mod_c2s
Florian Zeitz <florob@babelmonkeys.de>
parents:
857
diff
changeset
|
200 return ""; |
690
5acc203972f3
mod_websocket: Add fragmentation support
Florian Zeitz <florob@babelmonkeys.de>
parents:
689
diff
changeset
|
201 else |
5acc203972f3
mod_websocket: Add fragmentation support
Florian Zeitz <florob@babelmonkeys.de>
parents:
689
diff
changeset
|
202 log("warn", "Received frame with unsupported opcode %i", frame.opcode); |
895
1f4d77104da5
mod_websocket: Simplify by getting the c2s_listener from mod_c2s
Florian Zeitz <florob@babelmonkeys.de>
parents:
857
diff
changeset
|
203 return ""; |
690
5acc203972f3
mod_websocket: Add fragmentation support
Florian Zeitz <florob@babelmonkeys.de>
parents:
689
diff
changeset
|
204 end |
676
54fa9d6d7809
mod_websocket: New mod_c2s based version, still WIP
Florian Zeitz <florob@babelmonkeys.de>
parents:
129
diff
changeset
|
205 |
690
5acc203972f3
mod_websocket: Add fragmentation support
Florian Zeitz <florob@babelmonkeys.de>
parents:
689
diff
changeset
|
206 if frame.FIN then |
842
32df4d13f178
mod_websocket: More robust frame handling
Florian Zeitz <florob@babelmonkeys.de>
parents:
840
diff
changeset
|
207 data = dataBuffer; |
32df4d13f178
mod_websocket: More robust frame handling
Florian Zeitz <florob@babelmonkeys.de>
parents:
840
diff
changeset
|
208 dataBuffer = nil; |
690
5acc203972f3
mod_websocket: Add fragmentation support
Florian Zeitz <florob@babelmonkeys.de>
parents:
689
diff
changeset
|
209 |
895
1f4d77104da5
mod_websocket: Simplify by getting the c2s_listener from mod_c2s
Florian Zeitz <florob@babelmonkeys.de>
parents:
857
diff
changeset
|
210 return data; |
676
54fa9d6d7809
mod_websocket: New mod_c2s based version, still WIP
Florian Zeitz <florob@babelmonkeys.de>
parents:
129
diff
changeset
|
211 end |
895
1f4d77104da5
mod_websocket: Simplify by getting the c2s_listener from mod_c2s
Florian Zeitz <florob@babelmonkeys.de>
parents:
857
diff
changeset
|
212 return ""; |
842
32df4d13f178
mod_websocket: More robust frame handling
Florian Zeitz <florob@babelmonkeys.de>
parents:
840
diff
changeset
|
213 end |
32df4d13f178
mod_websocket: More robust frame handling
Florian Zeitz <florob@babelmonkeys.de>
parents:
840
diff
changeset
|
214 |
895
1f4d77104da5
mod_websocket: Simplify by getting the c2s_listener from mod_c2s
Florian Zeitz <florob@babelmonkeys.de>
parents:
857
diff
changeset
|
215 conn:setlistener(c2s_listener); |
1f4d77104da5
mod_websocket: Simplify by getting the c2s_listener from mod_c2s
Florian Zeitz <florob@babelmonkeys.de>
parents:
857
diff
changeset
|
216 c2s_listener.onconnect(conn); |
1f4d77104da5
mod_websocket: Simplify by getting the c2s_listener from mod_c2s
Florian Zeitz <florob@babelmonkeys.de>
parents:
857
diff
changeset
|
217 |
842
32df4d13f178
mod_websocket: More robust frame handling
Florian Zeitz <florob@babelmonkeys.de>
parents:
840
diff
changeset
|
218 local frameBuffer = ""; |
895
1f4d77104da5
mod_websocket: Simplify by getting the c2s_listener from mod_c2s
Florian Zeitz <florob@babelmonkeys.de>
parents:
857
diff
changeset
|
219 add_filter(sessions[conn], "bytes/in", function(data) |
1f4d77104da5
mod_websocket: Simplify by getting the c2s_listener from mod_c2s
Florian Zeitz <florob@babelmonkeys.de>
parents:
857
diff
changeset
|
220 local cache = ""; |
842
32df4d13f178
mod_websocket: More robust frame handling
Florian Zeitz <florob@babelmonkeys.de>
parents:
840
diff
changeset
|
221 frameBuffer = frameBuffer .. data; |
32df4d13f178
mod_websocket: More robust frame handling
Florian Zeitz <florob@babelmonkeys.de>
parents:
840
diff
changeset
|
222 local frame, length = parse_frame(frameBuffer); |
32df4d13f178
mod_websocket: More robust frame handling
Florian Zeitz <florob@babelmonkeys.de>
parents:
840
diff
changeset
|
223 |
32df4d13f178
mod_websocket: More robust frame handling
Florian Zeitz <florob@babelmonkeys.de>
parents:
840
diff
changeset
|
224 while frame do |
32df4d13f178
mod_websocket: More robust frame handling
Florian Zeitz <florob@babelmonkeys.de>
parents:
840
diff
changeset
|
225 frameBuffer = frameBuffer:sub(length + 1); |
895
1f4d77104da5
mod_websocket: Simplify by getting the c2s_listener from mod_c2s
Florian Zeitz <florob@babelmonkeys.de>
parents:
857
diff
changeset
|
226 local result = handle_frame(frame); |
1f4d77104da5
mod_websocket: Simplify by getting the c2s_listener from mod_c2s
Florian Zeitz <florob@babelmonkeys.de>
parents:
857
diff
changeset
|
227 if not result then return; end |
1f4d77104da5
mod_websocket: Simplify by getting the c2s_listener from mod_c2s
Florian Zeitz <florob@babelmonkeys.de>
parents:
857
diff
changeset
|
228 cache = cache .. result; |
842
32df4d13f178
mod_websocket: More robust frame handling
Florian Zeitz <florob@babelmonkeys.de>
parents:
840
diff
changeset
|
229 frame, length = parse_frame(frameBuffer); |
32df4d13f178
mod_websocket: More robust frame handling
Florian Zeitz <florob@babelmonkeys.de>
parents:
840
diff
changeset
|
230 end |
895
1f4d77104da5
mod_websocket: Simplify by getting the c2s_listener from mod_c2s
Florian Zeitz <florob@babelmonkeys.de>
parents:
857
diff
changeset
|
231 return cache; |
676
54fa9d6d7809
mod_websocket: New mod_c2s based version, still WIP
Florian Zeitz <florob@babelmonkeys.de>
parents:
129
diff
changeset
|
232 |
844
a0987c0e4e1d
mod_websocket: Check whether the xmpp sub-protocol was requested
Florian Zeitz <florob@babelmonkeys.de>
parents:
842
diff
changeset
|
233 end); |
a0987c0e4e1d
mod_websocket: Check whether the xmpp sub-protocol was requested
Florian Zeitz <florob@babelmonkeys.de>
parents:
842
diff
changeset
|
234 |
895
1f4d77104da5
mod_websocket: Simplify by getting the c2s_listener from mod_c2s
Florian Zeitz <florob@babelmonkeys.de>
parents:
857
diff
changeset
|
235 add_filter(sessions[conn], "bytes/out", function(data) |
1f4d77104da5
mod_websocket: Simplify by getting the c2s_listener from mod_c2s
Florian Zeitz <florob@babelmonkeys.de>
parents:
857
diff
changeset
|
236 return build_frame({ FIN = true, opcode = 0x01, data = tostring(data)}); |
1f4d77104da5
mod_websocket: Simplify by getting the c2s_listener from mod_c2s
Florian Zeitz <florob@babelmonkeys.de>
parents:
857
diff
changeset
|
237 end); |
842
32df4d13f178
mod_websocket: More robust frame handling
Florian Zeitz <florob@babelmonkeys.de>
parents:
840
diff
changeset
|
238 |
969
8eba9d4809d2
mod_websocket: Set status_code instead of status
Florian Zeitz <florob@babelmonkeys.de>
parents:
910
diff
changeset
|
239 response.status_code = 101; |
895
1f4d77104da5
mod_websocket: Simplify by getting the c2s_listener from mod_c2s
Florian Zeitz <florob@babelmonkeys.de>
parents:
857
diff
changeset
|
240 response.headers.upgrade = "websocket"; |
1f4d77104da5
mod_websocket: Simplify by getting the c2s_listener from mod_c2s
Florian Zeitz <florob@babelmonkeys.de>
parents:
857
diff
changeset
|
241 response.headers.connection = "Upgrade"; |
1f4d77104da5
mod_websocket: Simplify by getting the c2s_listener from mod_c2s
Florian Zeitz <florob@babelmonkeys.de>
parents:
857
diff
changeset
|
242 response.headers.sec_webSocket_accept = base64(sha1(request.headers.sec_websocket_key .. "258EAFA5-E914-47DA-95CA-C5AB0DC85B11")); |
1f4d77104da5
mod_websocket: Simplify by getting the c2s_listener from mod_c2s
Florian Zeitz <florob@babelmonkeys.de>
parents:
857
diff
changeset
|
243 response.headers.sec_webSocket_protocol = "xmpp"; |
1f4d77104da5
mod_websocket: Simplify by getting the c2s_listener from mod_c2s
Florian Zeitz <florob@babelmonkeys.de>
parents:
857
diff
changeset
|
244 response.headers.access_control_allow_origin = cross_domain; |
676
54fa9d6d7809
mod_websocket: New mod_c2s based version, still WIP
Florian Zeitz <florob@babelmonkeys.de>
parents:
129
diff
changeset
|
245 |
54fa9d6d7809
mod_websocket: New mod_c2s based version, still WIP
Florian Zeitz <florob@babelmonkeys.de>
parents:
129
diff
changeset
|
246 return ""; |
129 | 247 end |
676
54fa9d6d7809
mod_websocket: New mod_c2s based version, still WIP
Florian Zeitz <florob@babelmonkeys.de>
parents:
129
diff
changeset
|
248 |
688
e87678a52720
mod_websocket: Make this a shared module
Florian Zeitz <florob@babelmonkeys.de>
parents:
687
diff
changeset
|
249 function module.add_host(module) |
e87678a52720
mod_websocket: Make this a shared module
Florian Zeitz <florob@babelmonkeys.de>
parents:
687
diff
changeset
|
250 module:depends("http"); |
676
54fa9d6d7809
mod_websocket: New mod_c2s based version, still WIP
Florian Zeitz <florob@babelmonkeys.de>
parents:
129
diff
changeset
|
251 module:provides("http", { |
909
ec4c6e8f277d
mod_websocket: Change the HTTP name to websocket, and override the default_path instead
Florian Zeitz <florob@babelmonkeys.de>
parents:
905
diff
changeset
|
252 name = "websocket"; |
ec4c6e8f277d
mod_websocket: Change the HTTP name to websocket, and override the default_path instead
Florian Zeitz <florob@babelmonkeys.de>
parents:
905
diff
changeset
|
253 default_path = "xmpp-websocket"; |
676
54fa9d6d7809
mod_websocket: New mod_c2s based version, still WIP
Florian Zeitz <florob@babelmonkeys.de>
parents:
129
diff
changeset
|
254 route = { |
849
6e2ec1825182
mod_websocket: Accept GET request without trailing /
Florian Zeitz <florob@babelmonkeys.de>
parents:
844
diff
changeset
|
255 ["GET"] = handle_request; |
6e2ec1825182
mod_websocket: Accept GET request without trailing /
Florian Zeitz <florob@babelmonkeys.de>
parents:
844
diff
changeset
|
256 ["GET /"] = handle_request; |
676
54fa9d6d7809
mod_websocket: New mod_c2s based version, still WIP
Florian Zeitz <florob@babelmonkeys.de>
parents:
129
diff
changeset
|
257 }; |
54fa9d6d7809
mod_websocket: New mod_c2s based version, still WIP
Florian Zeitz <florob@babelmonkeys.de>
parents:
129
diff
changeset
|
258 }); |
129 | 259 end |