# HG changeset patch # User Kim Alvefur # Date 1480849046 -3600 # Node ID e0e1f6d6fb4f43a3f608c89a5f9f173a12a7d08c # Parent 801d4c8e0f58e165be48c32b78af5457af89dfcb mod_websocket: Use contains_token from util.http for checking if the requested WebSocket sub-protocols include XMPP diff -r 801d4c8e0f58 -r e0e1f6d6fb4f plugins/mod_websocket.lua --- a/plugins/mod_websocket.lua Sun Dec 04 11:52:22 2016 +0100 +++ b/plugins/mod_websocket.lua Sun Dec 04 11:57:26 2016 +0100 @@ -14,6 +14,7 @@ local base64 = require "util.encodings".base64.encode; local st = require "util.stanza"; local parse_xml = require "util.xml".parse; +local contains_token = require "util.http".contains_token; local portmanager = require "core.portmanager"; local sm_destroy_session = require"core.sessionmanager".destroy_session; local log = module._log; @@ -142,10 +143,7 @@ ]]; end - local wants_xmpp = false; - (request.headers.sec_websocket_protocol or ""):gsub("([^,]*),?", function (proto) - if proto == "xmpp" then wants_xmpp = true; end - end); + local wants_xmpp = contains_token(request.headers.sec_websocket_protocol or "", "xmpp"); if not wants_xmpp then module:log("debug", "Client didn't want to talk XMPP, list of protocols was %s", request.headers.sec_websocket_protocol or "(empty)");