Mercurial > prosody-modules
comparison mod_websocket/mod_websocket.lua @ 1193:bbe278a56b0a
mod_websocket: Add consider_websocket_secure option
| author | Florian Zeitz <florob@babelmonkeys.de> |
|---|---|
| date | Wed, 18 Sep 2013 00:57:06 +0200 |
| parents | 9d85aded2fb6 |
| children | 717a08403b26 |
comparison
equal
deleted
inserted
replaced
| 1192:db4085433e5f | 1193:bbe278a56b0a |
|---|---|
| 23 | 23 |
| 24 local t_concat = table.concat; | 24 local t_concat = table.concat; |
| 25 local s_byte = string.byte; | 25 local s_byte = string.byte; |
| 26 local s_char= string.char; | 26 local s_char= string.char; |
| 27 | 27 |
| 28 local consider_websocket_secure = module:get_option_boolean("consider_websocket_secure"); | |
| 28 local cross_domain = module:get_option("cross_domain_websocket"); | 29 local cross_domain = module:get_option("cross_domain_websocket"); |
| 29 if cross_domain then | 30 if cross_domain then |
| 30 if cross_domain == true then | 31 if cross_domain == true then |
| 31 cross_domain = "*"; | 32 cross_domain = "*"; |
| 32 elseif type(cross_domain) == "table" then | 33 elseif type(cross_domain) == "table" then |
| 238 end | 239 end |
| 239 | 240 |
| 240 conn:setlistener(c2s_listener); | 241 conn:setlistener(c2s_listener); |
| 241 c2s_listener.onconnect(conn); | 242 c2s_listener.onconnect(conn); |
| 242 | 243 |
| 244 local session = sessions[conn]; | |
| 245 | |
| 246 session.secure = consider_websocket_secure or session.secure; | |
| 247 | |
| 243 local frameBuffer = ""; | 248 local frameBuffer = ""; |
| 244 add_filter(sessions[conn], "bytes/in", function(data) | 249 add_filter(session, "bytes/in", function(data) |
| 245 local cache = {}; | 250 local cache = {}; |
| 246 frameBuffer = frameBuffer .. data; | 251 frameBuffer = frameBuffer .. data; |
| 247 local frame, length = parse_frame(frameBuffer); | 252 local frame, length = parse_frame(frameBuffer); |
| 248 | 253 |
| 249 while frame do | 254 while frame do |
| 254 frame, length = parse_frame(frameBuffer); | 259 frame, length = parse_frame(frameBuffer); |
| 255 end | 260 end |
| 256 return t_concat(cache, ""); | 261 return t_concat(cache, ""); |
| 257 end); | 262 end); |
| 258 | 263 |
| 259 add_filter(sessions[conn], "bytes/out", function(data) | 264 add_filter(session, "bytes/out", function(data) |
| 260 return build_frame({ FIN = true, opcode = 0x01, data = tostring(data)}); | 265 return build_frame({ FIN = true, opcode = 0x01, data = tostring(data)}); |
| 261 end); | 266 end); |
| 262 | 267 |
| 263 response.status_code = 101; | 268 response.status_code = 101; |
| 264 response.headers.upgrade = "websocket"; | 269 response.headers.upgrade = "websocket"; |
